【问题标题】:Error using React.memo() over stateless component在无状态组件上使用 React.memo() 时出错
【发布时间】:2018-10-31 15:06:24
【问题描述】:

使用 react 16.6 我正在尝试将备忘录与无状态组件一起使用,但出现错误。

错误

react-dom.development.js:57 未捕获的错误:元素类型无效:预期为字符串(用于内置组件)或类/函数(用于复合组件)但得到:对象。 em>

代码:

const MyComponent = () => (
  <React.Fragment>
    TEST
  </React.Fragment>
);

export default React.memo(MyComponent);

【问题讨论】:

  • 我认为箭头函数右侧需要大括号{ }
  • 不得不禁用美化器来测试,没有用(

标签: reactjs


【解决方案1】:

您也应该将react-dom 更新为^16.6.0 版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2018-08-13
    相关资源
    最近更新 更多