简体   繁体   English

Reactjs:避免每次更新都重新渲染组件 state

[英]Reactjs: avoird rerender component for every update state

This is my code:这是我的代码:

<SymbolOverview colorTheme="light"
    autosize
    symbols={[["COINBASE:" + symbol1 + "USD"]]}
    wickDownColor="#F45B7E" />

<SymbolOverview colorTheme="light"
    autosize
    symbols={[["COINBASE:" + symbol2 + "USD"]]}
    wickDownColor="#F45B7E" />

If I set setSymbole1("BTC") , my component for symbol2 changed too.如果我设置setSymbole1("BTC") ,我的symbol2组件也会改变。

I want only re render component for symbol1 .我只想重新渲染symbol1的组件。

By googling I found useMemo and useCallback, but I cant understand these.通过谷歌搜索,我找到了 useMemo 和 useCallback,但我无法理解这些。

If you components in the same page, When all page will be rendering which mean both of them will be rendering.如果你在同一个页面中的组件,当所有页面都被渲染时,这意味着它们都将被渲染。

What you do it's use debounce to change the state "on the fly" for one component.您所做的是使用debounce为一个组件“即时”更改 state。

ref: https://www.freecodecamp.org/news/javascript-debounce-example/参考: https://www.freecodecamp.org/news/javascript-debounce-example/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM