Created
October 28, 2019 14:53
-
-
Save riccardogiorato/3548d351cd36f008e2efeadd7349cd5d 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
import React, { useEffect } from "react"; | |
export const AppStateContext = React.createContext(null); | |
export default function AppStateProvider({ children }) { | |
const [message, SetMessage] = React.useState(); | |
const [error, SetError] = React.useState(); | |
const state = { | |
SetMessage: SetMessage, | |
SetError: SetError | |
}; | |
useEffect(() => { | |
if (message !== undefined) alert(message); | |
}, [message]); | |
useEffect(() => { | |
if (error !== undefined) alert(error); | |
}, [error]); | |
return ( | |
<AppStateContext.Provider value={state}> | |
{children} | |
</AppStateContext.Provider> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment