Created
May 2, 2020 06:31
-
-
Save sagar-gavhane/186673c63fb17471f6fec7e9dbfb0d7d to your computer and use it in GitHub Desktop.
#3 React.memo with react-fast-compare
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
import React from 'react' | |
import { render } from 'react-dom' | |
import isEqual from 'react-fast-compare' | |
function Input(props) { | |
return <input value={props.value} onChange={props.handleOnChange} /> | |
} | |
const MemoizedInput = React.memo(Input, isEqual) | |
function App() { | |
const [username, setUsername] = React.useState('') | |
const handleOnChange = React.useCallback((e) => { | |
setUsername(e.target.value) | |
}, []) | |
return <MemoizedInput value={username} handleOnChange={handleOnChange} /> | |
} | |
render(<App />, document.getElementById('root')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment