Last active
January 26, 2023 02:25
-
-
Save sekhyuni/ef4293b84c6914baa6bbf530a01c3abb to your computer and use it in GitHub Desktop.
[Test Code] Recursing On Children Related to Reconciliation
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, { 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