Last active
June 22, 2021 19:18
-
-
Save yuvalbl/49111ced0ff6f75975472ad2fbddd7f3 to your computer and use it in GitHub Desktop.
react_spread_attributes
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
function App1() { | |
return <Greeting firstName="Ben" lastName="Hector" />; | |
} | |
function App2() { | |
const props = { firstName: 'Ben', lastName: 'Hector' }; | |
return <Greeting {...props} />; | |
} |
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
const useFormInput = (initialValue) => { | |
const [value, setValue] = useState(initialValue); | |
const handleChange = (e) => { | |
setValue(e.target.value); | |
}; | |
return { | |
value, | |
onChange: handleChange | |
}; | |
}; | |
// usage | |
const App = () => { | |
const name = useFormInput('Mary'); | |
return ( | |
<div> | |
<input {...name} /> | |
<button className="action-button">x</button> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment