Last active
July 25, 2020 22:56
-
-
Save JenniferFuBook/e705c15bcee87a565643b5444d6009d8 to your computer and use it in GitHub Desktop.
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
| const useMyName = initialName => { | |
| const [currentName, setCurrentName] = React.useState(initialName); | |
| return [ | |
| newName => setCurrentName(newName), | |
| `My name is ${currentName}.`, | |
| ['Jack', 'Larry', 'Tom'].map(item =>[ | |
| <label key={item}> | |
| <input | |
| type="radio" | |
| name="names" | |
| data-testid={item} | |
| value={item} | |
| checked={currentName === item} | |
| onChange={() => setCurrentName(item)} | |
| /> | |
| {item} | |
| <br /> | |
| </label>, | |
| ]) | |
| ]; | |
| } | |
| const App = () => { | |
| const [, message, display] = useMyName('Larry'); | |
| return ( | |
| <> | |
| {display} | |
| <div>{message}</div> | |
| </> | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment