Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将基于类的生命周期方法转换为函数方法?_Javascript_Reactjs_React Native_Class_Expo - Fatal编程技术网

Javascript 如何将基于类的生命周期方法转换为函数方法?

Javascript 如何将基于类的生命周期方法转换为函数方法?,javascript,reactjs,react-native,class,expo,Javascript,Reactjs,React Native,Class,Expo,在以下代码中: componentDidMount(){ registerForPushNotificationsAsync(); this.\u notificationSubscription=Notifications.addListener(this.\u handleNotification); } 分配Notifications.addListener(此.\u handleNotification)与分配Notifications.addListener有什么区别到这个。_not

在以下代码中:

componentDidMount(){
registerForPushNotificationsAsync();
this.\u notificationSubscription=Notifications.addListener(this.\u handleNotification);
}
分配
Notifications.addListener(此.\u handleNotification)与分配
Notifications.addListener有什么区别
这个。_notificationSubscription
然后简单地去:

componentDidMount(){
registerForPushNotificationsAsync();
Notifications.addListener(此.\u handleNotification);
}
另外,如何将其转换为如下所示的功能组件格式

useffect(()=>{
registerForPushNotificationsAsync();
通知。addListener(handleNotification);
}, []);
有关此链接的更多信息:
useEffect(() => {
        registerForPushNotificationsAsync();
        const subscription =Notifications.addListener(handleNotification);
        return () => {
            // Call method for clear subscription. I asume that it is remove but it can be another
            subscription.remove()
        }
    }, []);