State:

For Example,

class Test extends React.Component {    
constructor() {
this.state = {
id: 1,
name: "kaashiv"
};
}

render() {
return (
<div>
<p>{this.state.id}</p>
<p>{this.state.name}</p>
</div>
);
}
}

Props:

For Example,

class ParentComponent extends Component {    
render() {
return (
<ChildComponent name="Second Child" />
);
}
}

const ChildComponent = (props) => {
return <p>{props.name}</p>;

Difference between State and Props :

                     State                      Props
Data passed within the component only.  Data passed from one component To another.
It becomes Mutable.  It becomes immutable
It is for both read and write.  It is only for read.
It becomes long for properties. It becomes short for properties.
It can be modified. It cannot be modified.
Performance is worse. Performance is better.
It should be managed in your view-controller It is used to pass data down from your view-controller
It pass down with props instead. It is used to pass data to child components.

Categorized in:

ReactJS

Tagged in:

, , , , , , , , , , , , , , , , ,

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock