相关疑难解决方法(0)

当我在父级中使用 HOC 时,React 会重新渲染我的记忆组件

我遇到了图像闪烁的问题,因为尽管使用了 React.memo,而且它的 props 或状态都没有改变,但它还是无缘无故地渲染了。

在这里成功地正确使用了 React.memo 来完成这项工作,BUUUT,出于我不明白的原因,如果我在父组件中使用高阶组件,备忘录将不再工作,我得到我的眨眼问题又来了。

这里有一个小吃很能说明问题

这是代码:

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';

let interval = null

const Icon = ({ name }) => {
  // We emulate a rerender of the Icon by logging 'rerender' in the console
  console.log('rerender')
  return <Text>{name}</Text>
}

const Memo = React.memo(Icon, () => true)

const withHOC = (Comp) => (props) => {
  return <Comp {...props}/>
}

export default function App() { …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-hooks

1
推荐指数
1
解决办法
1473
查看次数

标签 统计

react-hooks ×1

react-native ×1

reactjs ×1