-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example in ReadMe should explain how to use context #72
Comments
@nuclearspike I'm trying to implement it here with the |
in Landing.js you need to declare that you want that context available to static contextTypes = { I'd also move the "<NotificationSystem " line up to the top in the Container. Are you trying to do the The "notifications" field of the Container component isn't set until that component If we'd named the function that gets exposed through the context something different, then it would be more obvious where the failure is. |
Is this the recommended way of providing global notifications for the notif-system in a non-flux app? I know that the context system in React is an experimental API and there are warnings against using it but we see libs like Material-ui and router making using of context. react-notification-system could provide a For example: Notification Provider
A component somewhere in your app
App entry point
Note, compares to earlier example that exposes addNotification, here we pass the entire notificationSystem in context, then we can call any of the notification system functions. Also, had to use a function to return the notification system, rather than passing the notificationSystem itself. I think this is because the context may provided before the provided has mounted (so, |
@nuclearspike, thanks for the React Context suggestion ! (new file) NotifierAppContainer.tsx
(updated) boot.tsx
usage in AnyComponent.tsx
|
Rather than worrying about how to integrate with Redux/Flux/Reflux/etc, I've found the best way to integrate this with a single page app is to use context.
Given this structure in my App container component's render:
Side note: you can pass a function to ref rather than setting it in a lifecycle method like "componentDidMount" (as shown in the example code).
Then you put this in the App component...
Then, when any child component that is rendered inside the App component declares a context type like so:
Then you can call it like this in that child component:
Using context is easier, IMO, than using a redux/reflux/flux because this component was made to have a function called rather than have its state set, which context is much better for.
The text was updated successfully, but these errors were encountered: