Skip to content

Instantly share code, notes, and snippets.

@quisido
Created December 3, 2018 15:05
Show Gist options
  • Save quisido/ea47ba3176bc5709ca532497fa4b4496 to your computer and use it in GitHub Desktop.
Save quisido/ea47ba3176bc5709ca532497fa4b4496 to your computer and use it in GitHub Desktop.
Manage global state with React Hooks
const MyComponent = () => {
const [ global, setGlobal ] = useGlobal();
return (
<img
alt="Avatar"
onClick={() => {
const newAvatar = prompt("Enter your avatar URL:");
setGlobal({
avatar: newAvatar
});
}}
src={global.avatar}
/>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment