我遇到了图像闪烁的问题,因为尽管使用了 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)