Skip to content

Instantly share code, notes, and snippets.

@mistakster
Last active October 22, 2021 13:56
Show Gist options
  • Save mistakster/d84d8f7e931fe5e19c53ea2b82b89f41 to your computer and use it in GitHub Desktop.
Save mistakster/d84d8f7e931fe5e19c53ea2b82b89f41 to your computer and use it in GitHub Desktop.
The test case for interview discussion (React developer)
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