error using one Signal React Nenable

Asked

Viewed 43 times

0

I’m trying to use onesignal with typescript but I can’t. Every time I run the application it error and the vs code itself keeps pointing error but I can’t resolve... I followed the tutorial in Youtube and there is no way to solve.

Part of the mistake:

  useEffect( () => {
OneSignal.init("My Code");

OneSignal.addEventListener('opened', onOpened);

return () => OneSignal.removeEventListener('opened', onOpened)

})

  function onOpened(result: any) {
    console.log('Message: ', result.notification.payload.body);
    console.log('openResult: ', result);
  }

App component:

import React, { useEffect } from "react";
import { 
    useFonts,
    Inter_300Light,
    Inter_400Regular,
    Inter_500Medium,
    Inter_600SemiBold,
    Inter_700Bold
} from "@expo-google-fonts/inter";
import { Text } from "react-native";
import OneSignal from 'react-native-onesignal';


import Routes from "./src/routes/index";




export default function App() {
  const [ fontsLoaded ] = useFonts({
    Inter_300Light,
    Inter_400Regular,
    Inter_500Medium,
    Inter_600SemiBold,
    Inter_700Bold
  });

  useEffect( () => {
    OneSignal.init("My Code");

    OneSignal.addEventListener('opened', onOpened);

    return () => OneSignal.removeEventListener('opened', onOpened)
  })

  function onOpened(result: any) {
    console.log('Message: ', result.notification.payload.body);
    console.log('openResult: ', result);
  }

  
 
  if (!fontsLoaded) 
    return <Text>Carregando...</Text>;

  return (
    <Routes />
  );
};

Error

    TypeError: _reactNativeOnesignal.default.init is not a function. (In '_reactNativeOnesignal.default.init("3d011c32-7da8-4939-9ee0-b12a154037da")', '_reactNativeOnesignal.default.init' is undefined)

This error is located at:
    in App (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException
at node_modules/react-native/Libraries/Core/ReactFiberErrorDialog.js:43:2 in showErrorDialog
at [native code]:null in commitRootImpl
at [native code]:null in performSyncWorkOnRoot
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:54:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:117:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:213:4 in runApplication
at [native code]:null in callFunctionReturnFlushedQueue

TypeError: _reactNativeOnesignal.default.init is not a function. (In '_reactNativeOnesignal.default.init("3d011c32-7da8-4939-9ee0-b12a154037da")', '_reactNativeOnesignal.default.init' is undefined)

This error is located at:
    in App (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:45)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:106)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
at [native code]:null in dispatchAction
at node_modules/@expo-google-fonts/inter/useFonts.js:21:27 in loadAsync.then$argument_0
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

If anyone can help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.