You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my personal point of view.
Do not accept without doubt.
Common Thought
The common thought of re-render is that ...
React component is re-rendered when states are changed.
React component is re-rendered when props are changed.
But that's not right.
When React Component Re-Render?
React component is re-rendered when states are changed.
React component is re-rendered when high-order component is re-rendered.
Props Change Does Not Affect Re-Render
Evidence 1
constApp=()=>{const[name,setName]=useState('hong')const[age,setAge]=useState(1)constchangeName=()=>setName(name+'h')constchangeAge=()=>setAge(age+1)return[<divkey="1">current name : {name}</div>,<divkey="2">current age : {age}</div>,<buttonkey="3"onClick={changeName}>change name</button>,<buttonkey="4"onClick={changeAge}>change age</button>,<Bkey="5"name={name}age={age}/>]}constB=({ name, age })=>{return[<h1key="1">hi! i'm B, {name}</h1>,<Akey="2"age={age}/>]}constA=({ age })=>{return<h1>{age}</h1>}
This is the test app of react re-render.
When name is changed, A is re-rendered.
Although A is not relevant with "name", but it is re-rendered, because B is high order component of A.
Evidence 2
// App.jsxconstApp=()=>{const[name,setName]=useState('hong')const[age,setAge]=useState(1)constchangeName=()=>setName(name+'h')constchangeAge=()=>setAge(age+1)return[<divkey="1">current name : {name}</div>,<divkey="2">current age : {age}</div>,<buttonkey="3"onClick={changeName}>change name</button>,<buttonkey="4"onClick={changeAge}>change age</button>,<Bkey="5"name={name}age={age}/>]}// B.jsxconstB=({ name, age })=>{return[<h1key="1">hi! i'm B, {name}</h1>,<Akey="2"age={age}/>]}constmemoizedB=memo(B,(prev,next)=>{const{name : prevName}=prevconst{name : nextName}=nextreturnprevName===nextName})export{memoizedBasB}// A.jsxconstA=({ age })=>{return<h1>{age}</h1>}export{A}
This is the another react app.
Although age is changed, A would not be re-rendered.
'Age is changed' means the props of the A is changed, but re-render is not triggered. Why?
Because the high order component of A(=B) is not re-rendered.
The text was updated successfully, but these errors were encountered:
Intro
This is my personal point of view.
Do not accept without doubt.
Common Thought
The common thought of re-render is that ...
But that's not right.
When React Component Re-Render?
Props Change Does Not Affect Re-Render
Evidence 1
This is the test app of react re-render.
When name is changed, A is re-rendered.
Although A is not relevant with "name", but it is re-rendered, because B is high order component of A.
Evidence 2
This is the another react app.
Although age is changed, A would not be re-rendered.
'Age is changed' means the props of the A is changed, but re-render is not triggered. Why?
Because the high order component of A(=B) is not re-rendered.
The text was updated successfully, but these errors were encountered: