react-native-notifier icon indicating copy to clipboard operation
react-native-notifier copied to clipboard

Use context

Open nandorojo opened this issue 2 years ago • 1 comments

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.

nandorojo avatar Jul 23 '21 20:07 nandorojo

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} />
    </>
  );
}

seniv avatar Jul 24 '21 08:07 seniv