如何在 react-redux connect 中使用 React.memo?

5 浏览
0 Comments

如何在 react-redux connect 中使用 React.memo?

有人知道如何在使用react-redux的connect函数时,将React组件包装在React.memo中吗?

例如,你会如何修改以下代码?

let Button = (props: Props) => (
  
);
Button = connect(
  mapStateToProps,
  mapDispatchToProps
)(Button);

我尝试过以下代码:

let Button = React.memo((props: Props) => (
  
));
Button = connect(
  mapStateToProps,
  mapDispatchToProps
)(Button);

然而,connect返回的函数期望传递一个组件,所以它会报错:

Uncaught Error: You must pass a component to the function returned by

connect. Instead received {"compare":null}

0