Last active
October 22, 2021 13:56
-
-
Save mistakster/d84d8f7e931fe5e19c53ea2b82b89f41 to your computer and use it in GitHub Desktop.
The test case for interview discussion (React developer)
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 { useState } from 'react'; | |
// 1) The following code is not optimal in terms | |
// of performance. Could you improve it? | |
const Page = () => { | |
const [value, setValue] = useState(0); | |
return ( | |
<Counter | |
value={value} | |
increase={() => setValue(value + 1)} | |
/> | |
); | |
}; | |
// 2) You need to figure out which properties are | |
// causing this component to re-render and why. | |
// 3) Could you implement a generic function | |
// that can do such detections? | |
const Counter = (props) => { | |
const { value, increase } = props; | |
return ( | |
<div> | |
<span>{value}</span> | |
{' '} | |
<button onClick={increase}>+1</button> | |
</div> | |
); | |
}; | |
export default Page; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment