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
import{Button}from'antd'import{useState,lazy}from'react'// import BigListPureComponent from './32.1.BigListPureComponent' // wdyr workconstBigListPureComponent=lazy(// wdyr workasync()=>awaitimport('./32.1.BigListPureComponent'))exportconstTest=()=>{const[count,setCount]=useState(0)/* use the hook instead of the const to prevent ** "BigListPureComponent" from re-rendering wit this component */// const bigListStyle = React.useMemo(() => ({ width: "100%" }), [])constbigListStyle={width: '100%',}return(<divclassName="Main"><h1>Big List (Main Demo)</h1><p>
Open the console and notice how the heavy list re-renders on every click
on Increase! even though its props are the same.
</p><div><ButtononClick={()=>{setCount((c)=>c+1)}}>
Increase! Count: {count}</Button></div><BigListPureComponentstyle={bigListStyle}/></div>)}
import{memo}from'react'import{times}from'lodash'constBigListPureComponent=memo(({ style }: {style: Object})=>{console.log("BigListPureComponent Re-Render! - We don't want this to happen too often.")return(<divstyle={style}><h2>BigListPureComponent</h2><div>{times(1000).map((n)=>(<divkey={n}>Element #{n}</div>))}</div></div>)})BigListPureComponent.displayName='BigListPureComponent'exportdefaultBigListPureComponent
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: