重组纯或React.memo吗?

时间:2019-07-19 12:58:27

标签: reactjs react-native recompose

我在问自己React.memo是否与重组pure()完全相同...

fetch("url", {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
    "Content-Length": "data.length"
  },
  body: JSON.stringify({ api: "checkOtp", otp: "235656" })
})
  .then(response => response.json())
  .then(responsejson => {
    this.setState({
      isLoading: false,
      dataSource: responsejson.code
    });
  })
  .catch(err => {
    console.log(err);
  });

import { pure } from 'recompose';
export default pure(MyComp);

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

根据React documentation

React.memo is a higher order component. It’s similar to React.PureComponent but for function components instead of classes.

因此它们并非完全相同,但它们具有相同的目的。