Props and state in React

Props:

In react , props stands for properties, it is an object which is a passed attribute to a component .

When React sees an element representing a user-defined component, it passes JSX attributes to this component as a single object. We call this object “props”.

— React Documentation

Props allows components to communicate to each other . Component pass attributes to another component through props object .

In the above example , Student1 and Student2 communicate each other with name property as a prop.

Prop is read only . It means we cant create new props in the component after props is being passed.

State:

We need state to monitor changes in a component. Whatever changes in a component will be handled by state and the DOM rendering will handle the rest .

State can only be read by component itself and it is not globally declared .

Since it is to monitor changes, state is mutable. However, state is not directly mutable. To mutate state, you need to use function that mutate the state.

react , props stands for properties, it is an object which is a passed attribute to a component .

When React sees an element representing a user-defined component, it passes JSX attributes to this component as a single object. We call this object “props”.

— React Documentation

Props allows components to communicate to each other . Component pass attributes to another component through props object .

SHARE

Facebook Feed

Copyright © 2021 Shield Technologies (Private) Limited