如何在状态更改期间禁用事件
How to disable event during a state change
由于我的代码库很大,所以我不会添加示例。希望我的问题足够清楚。
我正在使用 react-chartjs-2 来创建圆环图。我注意到图表上的每个状态变化都可能触发和事件。我不知道如何防止图表呈现。
知道如何禁用此行为吗?
谢谢
如果您使用的是功能组件,则可以使用像 useMemo which prevent you from rendering certain child components from rerendering. If you are using a class component you could get use of life cycle shouldComponentUpdate
这样的钩子
我想,如果您的组件不呈现,它不会触发图表中的重新呈现,您可以将图表包装在一个新组件中,并根据您的条件使用 React.memo
来呈现或不呈现图表,但要避免使用 memo
呈现错误,这将是您用于提高性能的最后选择。
React is VERY fast and there are so many things I can think of for you
to do with your time that would be better than optimizing things like
this
由于我的代码库很大,所以我不会添加示例。希望我的问题足够清楚。
我正在使用 react-chartjs-2 来创建圆环图。我注意到图表上的每个状态变化都可能触发和事件。我不知道如何防止图表呈现。
知道如何禁用此行为吗?
谢谢
如果您使用的是功能组件,则可以使用像 useMemo which prevent you from rendering certain child components from rerendering. If you are using a class component you could get use of life cycle shouldComponentUpdate
这样的钩子我想,如果您的组件不呈现,它不会触发图表中的重新呈现,您可以将图表包装在一个新组件中,并根据您的条件使用 React.memo
来呈现或不呈现图表,但要避免使用 memo
呈现错误,这将是您用于提高性能的最后选择。
React is VERY fast and there are so many things I can think of for you to do with your time that would be better than optimizing things like this