-
Notifications
You must be signed in to change notification settings - Fork 0
[2020-06-09]React心得整理 #51
Description
componentDidUpdate的使用時機與使用方式:
So whenever the component has a state change it will autosave the data. There are other ways to implement it too. The componentDidUpdate is particularly useful when an operation needs to happen after the DOM is updated and the update queue is emptied. It's probably most useful on complex renders and state or DOM changes or when you need something to be the absolutely last thing to be executed.
I think the most common use-case is when you have other libraries (jQuery, D3...) that work directly on the DOM, coupled together with React. In such scenarios, if the other library needs to perform DOM transformations, you should use componentDidUpdate to ensure React's shadow DOM has been flushed to the real DOM.
來源:When to use React “componentDidUpdate” method?
- IIFE in inline style: