seniv / react-native-notifier

Fast and simple in-app notifications for React Native
MIT License
1.05k stars 60 forks source link

Use context #41

Open nandorojo opened 3 years ago

nandorojo commented 3 years ago

Hey, I'm running into an issue where I want to use multiple notificationwrappers. one of them is nested inside of another screen. However, it seems that rather than use react context, this lib just uses a single wrapper at the root of the app and renders from there. The issue with this is that it renders under modals. I tried adding another wrapper inside the modal, but this did nothing, since it's not a context provider, which would take precedent over any parent providers.

seniv commented 3 years ago

Hey, that makes sense to add the ability to control notifiers with context, I will implement this. For now, you can render NotifierRoot with useRef and create your own context provider. Something like this:

import { NotifierRoot } from 'react-native-notifier';

const NotifierContext = React.createContext(null);

function App() {
  const notifierRef = useRef();
  return (
    <>
      <NotifierContext.Provider value={notifierRef}>
        <RootNavigator />
      </ NotifierContext.Provider>
      <NotifierRoot ref={notifierRef} />
    </>
  );
}