Created
July 27, 2021 13:35
-
-
Save kylephughes/7524b6d7711c9be423a35619d7b1ffc9 to your computer and use it in GitHub Desktop.
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
// <App/> | |
export const NotificationContext = React.createContext({...}) | |
return ( | |
<NotificationContext.Provider value={{ notification, setNotification }}> | |
// any child component can consume these values directly | |
</NotificationContext.Provider> | |
) | |
// <Notification/> | |
import { useContext } from 'react' | |
export const Notification = (props) => { | |
const { notification } = useContext(NotificationContext) | |
} | |
// <FormComponent/> | |
import { useContext } from 'react' | |
export const FormComponent = (props) => { | |
const { setNotification } = useContext(NotificationContext) | |
const sendNotification = () => { | |
setNotification('Success') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment