Skip to content

[2020-06-09]React心得整理 #51

@pdji1602003

Description

@pdji1602003
  1. 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?

  1. IIFE in inline style:

來源:Using an if statement to apply inline style (React)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions