InterviewSolution
| 1. |
What Are State And Props In Reactjs? |
|
Answer» State is the place where the data COMES from. We must follow approach to make our state as simple as possible and minimize number of stateful components. For example, ten components that need data from the state, we should create one container component that will keep the state for all of them. The state starts with a default value and when a Component mounts and then suffers from mutations in time (BASICALLY generated from user EVENTS). A Component manages its own state internally, but—besides setting an initial state—has no business fiddling with the stateof its children. You could say the state is private. import React from 'react'; Props: They are immutable, this is why container component should define state that can be updated and changed. It is used to pass data down from our view-controller(our top LEVEL component). When we need immutable data in our component we can just add props to reactDOM.render() function. import React from 'react'; render() { } State is the place where the data comes from. We must follow approach to make our state as simple as possible and minimize number of stateful components. For example, ten components that need data from the state, we should create one container component that will keep the state for all of them. The state starts with a default value and when a Component mounts and then suffers from mutations in time (basically generated from user events). A Component manages its own state internally, but—besides setting an initial state—has no business fiddling with the stateof its children. You could say the state is private. import React from 'react'; Props: They are immutable, this is why container component should define state that can be updated and changed. It is used to pass data down from our view-controller(our top level component). When we need immutable data in our component we can just add props to reactDOM.render() function. import React from 'react'; render() { } |
|