Last active
November 1, 2018 03:02
-
-
Save jossmac/507d12329e30bc50b7b2f36de229ac23 to your computer and use it in GitHub Desktop.
Pseudo code for a provider component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Renderer from './Renderer'; | |
export const ToastContext = React.createContext(); | |
export class ToastProvider extends React.Component { | |
state = { toasts: [] } | |
add = (content) => { | |
this.setState(...); | |
} | |
remove = (id) => { | |
this.setState(...); | |
} | |
render() { | |
const context = { | |
add: this.add, | |
remove: this.remove, | |
} | |
return ( | |
<ToastContext.Provider value={context}> | |
{this.props.children} | |
<Renderer toasts={this.state.toasts} /> | |
</ToastContext.Provider> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment