Created
December 3, 2018 14:58
-
-
Save quisido/6ed31b2a6fd9ddb0ef1d86e952e9f2c8 to your computer and use it in GitHub Desktop.
Manage global state with React Hooks
This file contains hidden or 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 { useState } from 'react'; | |
const MyComponent = () => { | |
const [ avatar, setAvatar ] = useState('anonymous.png'); | |
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