State & Props

Zain Ahmed
2 min readOct 14, 2020

--

let do a discussion on State and props , may be you are as React developer familiar with this terms.

What is State

When you defining/creating a Component in React , you may need some states/variables which are have usage in current component let say a list of orders have to represent in a UI , so your current component is name as Table and it has state of data which will store the data of api response, so Data is the state of Table component now move to props,

Table component

in table you have to create a row for display each row for data, so you created a row separate component called Row now here’s come the logic , you fetch the data from api in Table component you set the response in Data state of table component and you map on data state, on map you return a Row component which now become the child component of Table and Table component is now called parent of Row component , here we build parent child relation, now on map return you pass item or whatever you table on map for each element of data you pas it to Row component as this,

now lets move to Row component

Row component

here you see as we use this.prop.row.name, the variable row in this.props is the single element of Table component state data we use it as prop on child component Row, so now we can say that the state of parent component may become prop of child component if we transfer the state to child component ,

hope you understand the concept of State and Props,

--

--

Zain Ahmed
Zain Ahmed

Written by Zain Ahmed

Hello everyone, I am Zain Anmed a software engineer by profession, passionate about trying different technologies and trying some other cool stuff.

No responses yet