当状态改变时,React Native 是否总是渲染一切?

Does react native always renders everything when state changes?

我想知道当状态发生变化时,是否只渲染受状态影响的组件及其所有子组件,或者“该组件所在的整个函数(return 部分)”。

例子

const [label,setLabel]=useState();
...
export default function MyFunc(){
...
  return (
      ...
      (more than 200 rows of code)
      ...
      (here i have the button)
      ...
      (more then 200 rows of code)
  )
}

当某处调用 setLabel 时,每当它发生时,React 是否会渲染所有内容,包括其他代码行?

是的。每当状态发生变化时,react 都会重新渲染组件。这就是react的概念。

如果您的组件在给定相同道具的情况下呈现相同的结果,您可以将其包装在对 React.memo 的调用中,以便在某些情况下通过记忆结果来提高性能。这意味着 React 将跳过渲染组件,并重用上次渲染的结果。

有关详细信息,请访问下面的 link、

https://reactjs.org/docs/react-api.html#reactmemo