carsonwah / react-native-push-notification-popup

A <NotificationPopup/> component for presenting your own push notification in react-native app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use this with functional component?

SPineapple opened this issue · comments

commented

So I figured using functional component with this approach, but no avail, and this is how i am doing it :


//createRef
const popup = useRef()

//componentDidMount
useEffect(() => {
    popup.show({
          appIconSource: require("./assets/icon.png"),
          appTitle: "Some App",
          timeText: "Now",
          title: "Hello World",
          body: "This is a sample message.\nTesting emoji 😀",
          slideOutTime: 5000
        });
  }, [])


//at the bottom of Components
<NotificationPopup ref={popup} />

I don't know where I am going wrong, the error says :
undefined is not a function (near '...popup.show...')

commented

Never mind sorry, I read the documentation carefully this time and it mentioned to put under navigation, and so I did, with useEffect and modified the usage of ref in my previous attempt to :

<NotificationPopup
            ref={ref => (popup.current = ref)}
          />

and then in useEffect:

pop.current.show({
..
})

it is working now globally like a charm ! :)