在父组件中存储状态而不导致重新渲染父组件?

时间:2021-01-09 22:02:53

标签: reactjs react-hooks react-state react-state-management

考虑以下虚拟代码:

<Parent>
    <Form>
        <ItemEditor onItemsAdded={setItemStateOnParent} />
        <button type="submit" onClick={() => saveItems()}>Save items</button>
     </Form>
</Parent>

所以我在 ItemEditor 组件中的 Form 中使用了一个组件 Parent。当调用 setItemStateOnParent 回调时,它会更改 Parent 中的某些状态,从而导致重新渲染 Parent。我不需要也不想要这种重新渲染 - 所有必要的渲染都是由 ItemEditor 完成的。那么,是否有某种状态/钩子可以存储跨 Parent 次重新渲染的值而不会导致 Parent 重新渲染?

0 个答案:

没有答案