相关疑难解决方法(0)

尽管使用备忘录并且没有更改任何道具,但仍会在功能组件中重新渲染子项

我有一个 Icon 组件,它绘制一个图标并且它正在闪烁,因为父级正在使其重新渲染。我不明白为什么会发生这种情况以及如何防止这种情况发生。

这是显示问题的小吃

我们使用 setInterval 模拟父更改。

我们通过在控制台中记录“rerender”来模拟图标重新渲染。

这是代码:

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


// or any pure javascript modules available in npm
let interval = null

const Child = ({name}) => {
  //Why would this child still rerender, and how to prevent it?
  console.log('rerender')
  return <Text>{name}</Text>
}
const ChildContainer = ({name}) => {
  const Memo = React.memo(Child, () => true)
  return <Memo name={name}/>
}

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

reactjs react-native react-hooks

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

标签 统计

react-hooks ×1

react-native ×1

reactjs ×1