// React는 기본적으로 state변경시 해당 컴포넌트 및 자식 컴포넌트 전부 rerender한다.
// bailout로직중 newProps === oldProps 여야만 컴포넌트를 랜딩하지 않는다.
// 하위 컴포넌트에 React.memo 적용시 알고리즘을 실행해서 랭딩한다.
// 자주 변하는 값은 필요없지만 업데이트가 적거나 static한 컴포넌트는 필요하다.
// 컴포넌트 자체에서 props, state, context변화가 없고 부모의 부모의 ..... key값이 변화가 없는데 rerender된다.
import React, { useState, useMemo } from "react";
const EffectComponent = () => {
console.log("render effect Component");
return <>effect Component</>;
};
// const a = <EffectComponent />
// const diff = (prevProps, nextProps) => {
// console.log(prevProps === nextProps);
// return prevProps === nextProps;
// }
// const MemoEffectComponent = React.memo(EffectComponent, diff);
const App = () => {
const [count, setCount] = useState(0); // state또는 context를 건드렸기 때문.
const onChange = (e) => {
setCount(count + 1);
};
// const b = useMemo(() => <EffectComponent />, [])
return (
<>
<h2>Register</h2>
<input onChange={onChange} />
<p>{count}</p>
<EffectComponent />
{/* {a} */}
{/* <MemoEffectComponent /> */}
</>
);
};
export default App;