Skip to content

Instantly share code, notes, and snippets.

@sekhyuni
Last active January 26, 2023 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sekhyuni/ef4293b84c6914baa6bbf530a01c3abb to your computer and use it in GitHub Desktop.
Save sekhyuni/ef4293b84c6914baa6bbf530a01c3abb to your computer and use it in GitHub Desktop.
[Test Code] Recursing On Children Related to Reconciliation
import React, { useState } from 'react';
const App = (): JSX.Element => {
const [values, updateValues] = useState<string[]>(['Duke', 'Villanova']);
return (
<>
<button onClick={() => updateValues(['Connecticut', ...values])}>
Press me
</button>
<ul>
{values.map((item: string) => (
// key를 넣지 않은 경우
// <ChildComponentMemo text={item} />
// key를 넣은 경우
<ChildComponentMemo key={item} text={item} />
))}
</ul>
</>
);
};
const ChildComponent = (props: { text: string }): JSX.Element => {
console.log('ChildComponent --> re-render');
return <li>{props.text}</li>;
};
const ChildComponentMemo = React.memo(ChildComponent);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment