How to pass the state of the parent feature in the child?

How to pass as parent to child component?
June 7th 19 at 14:46
1 answer
June 7th 19 at 14:48
Solution
<children state="{this.state}"></children>
it is when rendering the component in the parent?
And what should be in a child component. How will look the code?

class Children extends Component {
constructor(props) {
super(props);

this.state = props..... ??? how will be here?
}
} - zane.Watsi commented on June 7th 19 at 14:51
,
poprobuite so
class Children extends Component {
constructor(props) {
super(props);
 let state = this.props.state
console.log("state",state)
}
}
- Raquel.Labad commented on June 7th 19 at 14:54
not necessary to do so. If the child receives state from a parent, to change it, he must through colback, also passed from the parent. - Lenny.Botsfo commented on June 7th 19 at 14:57
well here was I just pass the value and not to write a function that will pass a value and change state son - Raquel.Labad commented on June 7th 19 at 15:00
I said to Igor, it is not necessary to do so:
this.state = this.props.state;
Your example did not comment. Did I want to say that it is better to use constand not let for immutable values. Increases the readability of code. Especially if it is complex. - Lenny.Botsfo commented on June 7th 19 at 15:03
,
that is, if you need a direct function
class Father extends Component {
constructor(props) {
super(props);
}

changeStateChilren(){
 this.refs.chilren.setValue("need value")
}

render(){
return(
 <children ref="chilren">
)
}
}




class Children extends Component {
constructor(props) {
super(props);
}


setValue(val){
 console.log("from father val",val)
}
}</children>
- Raquel.Labad commented on June 7th 19 at 15:06
Yes , will be a function of the cat will change the value, but I thought that if you change the state of the parent, the child will change too. Confused already((( - zane.Watsi commented on June 7th 19 at 15:09
well , you thought correctly
change of state will occur and render the value of the new state will be passed to the offspring
just the function to use when you don't need to drag all of new parent and need only a few variables or need to change the value of the descendant state - Raquel.Labad commented on June 7th 19 at 15:12
Thanks all huge for answers!! - zane.Watsi commented on June 7th 19 at 15:15
I enough that you click on the correct answer) not for that - Raquel.Labad commented on June 7th 19 at 15:18

Find more questions by tags ReactJavaScript