如反应官方文档中所述,将 Render Props 与 React.PureComponent 一起使用有什么问题?
what's the issue in using Render Props with React.PureComponent as mentioned in the react official docs?
有人可以更详细地解释一下为什么将 Render Props 与 React.PureComponent 一起使用会在每次渲染中为 render prop 生成一个新值吗?
文档link:https://reactjs.org/docs/render-props.html#use-render-props-for-cross-cutting-concerns
因为当 React 渲染时 -> mouse => (<Cat mouse={mouse}/>)
将成为每次渲染的新引用。
通过放置在另一个函数中的修复 renderTheCat
,它将是相同的。
另一种思考方式 (()=>{}) === (()=>{})
永远等于 false。因为 renderTheCat === renderTheCat
等于 true.
有人可以更详细地解释一下为什么将 Render Props 与 React.PureComponent 一起使用会在每次渲染中为 render prop 生成一个新值吗?
文档link:https://reactjs.org/docs/render-props.html#use-render-props-for-cross-cutting-concerns
因为当 React 渲染时 -> mouse => (<Cat mouse={mouse}/>)
将成为每次渲染的新引用。
通过放置在另一个函数中的修复 renderTheCat
,它将是相同的。
另一种思考方式 (()=>{}) === (()=>{})
永远等于 false。因为 renderTheCat === renderTheCat
等于 true.