英文:
How exactly is RN component rerendered when state changes?
问题
如果 b 被更改,那么 componentB 会重新渲染,但是 ComponentA 会不会重新渲染呢?或者只有当 a 发生变化时 ComponentA 才会重新渲染?
英文:
Let's say I have a global state defined in Redux which consists of an object as:
const data =
{
a: { value: 1, id: 1 },
b: { value: 2, id: 2 }
};
ComponentA defined in one file uses a, componentB defined in another file uses b. If b is changed, componentB is rerendered, but is ComponentA also rerendered? Or ComponentA will only rerender if a changes?
答案1
得分: 2
每个注册监听器以侦听此变量的组件在此变量更改时都会重新渲染
例如
redux
const initiateState =
{
a: { value: 1, id: 1 },
b: { value: 2, id: 2 }
};
componentA
const valueA = useSelector((state) => state.reducer.a)
当a变化时,componentA会重新渲染,b变化时则不会有任何操作。
英文:
every component that register listener to variable this will re-render when this variable change
for example
redux
const initiateState =
{
a: { value: 1, id: 1 },
b: { value: 2, id: 2 }
};
componentA
const valueA = useSelector((state) => state.reducer.a)
when a changed, componentA got re-rendered, b change -> do nothing
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论