Reactjs React功能/无状态纯组件

Reactjs React功能/无状态纯组件,reactjs,Reactjs,我开始在React中切换到功能性/无状态组件,如下所示 然而,我确实在react-chartjs-2重新绘制图表时遇到了问题,即使它们的数据没有改变。在我切换到功能组件之前,使用Reacts PureComponent很容易解决这个问题 有没有办法让React将PureComponent用于无状态函数 const ListGroup = props => { const {title, width} = (props); return ( <ul className

我开始在React中切换到功能性/无状态组件,如下所示

然而,我确实在react-chartjs-2重新绘制图表时遇到了问题,即使它们的数据没有改变。在我切换到功能组件之前,使用Reacts PureComponent很容易解决这个问题

有没有办法让React将PureComponent用于无状态函数

const ListGroup = props => {
  const {title, width} = (props);

  return (
    <ul className={"grid"} style={{width}}>
      <h1>{title}</h1>
      {props.children}
    </ul>
  )
}
const ListGroup=props=>{
常量{title,width}=(道具);
返回(
    {title} {props.children}
) }
自React v16.6.0以来,您可以使用:

对于v16.6.0之前的React版本,您可以使用(已停止但仍保持)并使用或更高阶组件包装组件:

import pure from 'recompose/pure';

const PureListGroup = pure(ListGroup);

如何使用React的PureComponent允许在不更改数据的情况下重新渲染?你是不是用一种生命周期方法强迫它?另外,你为什么想要这种行为?恰恰相反。我不希望它在道具没有改变的情况下重新渲染组件。PureComponents解决了react-chartjs-2导致的这个问题:)只是2019年的更新。您不再需要为此使用外部库。由于react 16.6
react.memo提供了一个高阶组件,用于:
import pure from 'recompose/pure';

const PureListGroup = pure(ListGroup);