reading-notes

Software Development Reading Notes

View on GitHub

Readings: State and Props

React lifecycle

img

Mounting When an instance of a component is being created and inserted into the DOM it occurs during the mounting phase. Constructor, static getDerivedStateFromProps, render, componentDidMount, and UNSAFE_componentWillMount all occur in this order during mounting.

order should be constructor, render, React Updates, componentDidMount, componentWillUnmount.

The componentDidMount() method allows us to execute the React code when the component is already placed in the DOM (Document Object Model). This method is called during the Mounting phase of the React Life-cycle i.e after the component is rendered.

React State Vs Props

img

can be any JavaScript data type from integers over objects to arrays

Props are used to pass data from one component to another. The state is a local data storage that is local to the component only and cannot be passed to other components.

React schedules a render every time the state of a component changes. that's re-render.

whenever we are working with any data, we always use state for storing that data which may be a string , number or any complex object.