props and context - react.js
athul jain

athul jain @athuljain

About: MERN STACK DEVELOPER HTML | CSS | JS | NODEJS | EXPRESS JS | REACT | REDUX JS | MONGODB

Joined:
Aug 14, 2023

props and context - react.js

Publish Date: Dec 4 '23
0 0

"context" and "props" are concepts used to manage and pass data between components.

Props (Properties):

** Props are a mechanism for passing data from a parent component to a child component in a unidirectional flow.**

Direction of Data Flow: Data flows from parent to child components only.
Usage: Parent components pass data as props to child components, and child components receive and use these props.
Immutability: Props are immutable, meaning that child components cannot directly modify the props they receive from their parent.

Context:

Context provides a way to share values like themes, authentication status, etc., between components without explicitly passing them through props.

Direction of Data Flow: Context allows for more flexible data flow, as it enables sharing data with components that are not direct parent or child relationships.
Usage: Context is used when you have data that needs to be accessed by many components at different levels in the component tree.
** Immutability:** While context itself is not inherently immutable, the values provided through context can be treated as immutable to prevent unexpected behavior.

Comments 0 total

    Add comment