无法在React Native应用程序中使用React.memo

Roh*_*sal 9 reactjs react-native

我想在反应原生中使用React.memo进行优化.

import React from "react";
import { View, Text } from "react-native";

const Memo = React.memo(function() {
  return (
    <View>
      <Text>Ok</Text>
    </View>
  );
});
class Demo extends React.Component {
  render() {
    return <Memo />;
  }
}

export default Demo;
Run Code Online (Sandbox Code Playgroud)

它给出以下错误:

TypeError:undefined不是函数(求值render(nextProps)).此错误位于:在RCTView中的Demo(在renderApplication.js:34中)(在View.js:44)

我们可以在反应原生中使用React.memo吗?

小智 0

const MyFunctionComponent = ({text}) => <Text>{text}</Text>;

MyFunctionComponent.displayName = 'HarmlessComponent';
MyFunctionComponent.propTypes = {text: PropTypes.string.isRequired};

export default React.memo(MyFunctionComponent);
Run Code Online (Sandbox Code Playgroud)

  • 请使用提供的工具格式化您答案中的代码。仅代码答案几乎总是可以通过解释代码及其解决问题的方式来改进。 (2认同)