useeffect only on mount
import React, { useEffect } from 'react';
function App() {
useEffect(() => {
// Run! Like go get some data from an API.
}, []);
}
useeffect only on mount
import React, { useEffect } from 'react';
function App() {
useEffect(() => {
// Run! Like go get some data from an API.
}, []);
}
"useEffect" is read-only.
const App = () =>{
useEffect = (() =>{
getToken();
createChannel();
notificationlistner();
},[])
const getToken = async () => {
const fcmToken = await messaging().getToken();
console.log(fcmToken);
};
const createChannel = () =>{
const channel = new firebase.notifications.Android.createChannel(
'channelId',
'channelName',
firebase.notifications.Android.Importance.Max
).setDescription('Description');
firebase.notifications().Android.createChannel(channel);
};
const notificationlistner = () => {
firebase.notifications().onNotification((notification) =>{
if(Platform.OS === 'android'){
const localNotification = new firebase.notifications.Notification({
sound : 'default',
show_in_forground : true,
})
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setSubtitle(notification.subtitle)
.setBody(notification.body)
.setData(notification.data)
.android.setChannelId('channelId')
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(localNotification)
.catch((err) => console.log(err))
}
});
};
"useEffect" is read-only.
const App = () =>{
useEffect = (() =>{
getToken();
createChannel();
notificationlistner();
},[])
const getToken = async () => {
const fcmToken = await messaging().getToken();
console.log(fcmToken);
};
};
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us