DEV Community

Cover image for props and context - react.js
athul jain
athul jain

Posted on

props and context - react.js

"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.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay