Skip to content

Instantly share code, notes, and snippets.

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