Answers for ""useEffect" is read-only."

2

useeffect only on mount

import React, { useEffect } from 'react';

function App() {
  useEffect(() => {
    // Run! Like go get some data from an API.
  }, []);
}
Posted by: Guest on April-08-2020
0

"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))
        }
    });
  };
Posted by: Guest on June-16-2021
0

"useEffect" is read-only.

const App = () =>{

  useEffect = (() =>{
    getToken();
    createChannel();
    notificationlistner();
  },[])

  const getToken = async () => {
    const fcmToken = await messaging().getToken();  
     console.log(fcmToken);
  };

 
  };
Posted by: Guest on June-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language