React Part 4 Flashcards
Controlled components
A component that controls the input elements within the forms on subsequent user input
Uncontrolled components
The one that store their own state internally, query dom to find its ref
What is Lifting State Up in React?
When several components need to share the same changing data then it is recommended to lift the shared state up to their closest common ancestor
Different phases of lifecycles ?
Mounting: The component is ready to mount in the browser DOM
Updating: In this phase, the component gets updated in two ways, sending the new props and updating the state
Unmounting: In this last phase, the component is not needed and gets unmounted from the browser DOM.
componentWillReceiveProps
Executed when particular prop updates to trigger state transitions.
shouldComponentUpdate:
Determines if the component will be updated or not. (default: true, set to false to prevent a re-render when component receives new prop)
ComponentWillUpdate
execute before re-rendering components when state/props changes comfirmed by shouldComponentUpdate return true
componentDidUpdate
Mostly it is used to update the DOM in response to prop or state changes.
getDerivedStateFromProps
Invoked right before calling render() and is invoked on every render (rarely use)
Higher Order Components
A higher-order component (HOC) is a function that takes a component and returns a new component.
Stateless Component
If the behaviour is independent of its state then it can be a stateless component
What are stateful components?
If the behaviour of a component is dependent on the state of the component then it can be termed as stateful component.
React Composition
development pattern built based on React’ original component model where we build components from other components using explicit defined prop or implicit children prop.
Why use React Composition ?
This technique prevents us from building too many similar components containing duplicate code and allows us to build fewer components that can be reused anywhere within our application,
Specialized Components
A specialized component is a component that is built from its accepted props to handle one specific case.