Giter Club home page Giter Club logo

react-lifecycle-starter-code's Introduction

React Component Lifecycle

Docs

React Lifecycle Methods Diagram

What should I know

  • constructor(props)
  • render()
  • componentDidMount()
  • componentDidUpdate()
  • componentWillUnmount()

Birth (Mounting)

  • constructor(props)
    • called before it is mounted
  • static getDerivedStateFromProps(props, state)
    • invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.
  • render()
  • componentDidMount()
    • invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.

Life (Updating)

  • static getDerivedStateFromProps(props, state)
    • invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.
  • shouldComponentUpdate(nextProps, nextState)
    • invoked before rendering when new props or state are being received
    • returns boolean which determines if render should be called
  • render()
  • getSnapshotBeforeUpdate(prevProps, prevState)
    • invoked right before the most recently rendered output is committed to e.g. the DOM. It enables your component to capture some information from the DOM (e.g. scroll position) before it is potentially changed. Any value returned by this lifecycle will be passed as a parameter to componentDidUpdate()
  • componentDidUpdate(prevProps, prevState)
    • invoked immediately after updating occurs. This method is not called for the initial render
    • watch out for infinite loops if setting state!

Death (Unmounting)

  • componentWillUnmount()
    • invoked immediately before a component is unmounted and destroyed. Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests, or cleaning up any subscriptions that were created in componentDidMount().

react-lifecycle-starter-code's People

Contributors

betalantz avatar scrabill avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.