I have a react class that has this code:
getInitialState: function(){
return {
results: false,
value: ''
};
},
handleClick: function(event) {
this.setState({ results: true });
event.preventDefault();
},
handleChange: function(event){
this.setState({value: event.target.value})
},
<input type="text" id="playerName" value={this.state.value} onChange={this.handleChange} placeholder="name" />
IN ANOTHER REACT CLASS
I have:
myFunc: function() {
this.setState({info: true})
let name = this.props.value;
console.log(name) --> returns undefined
},
How can I name to be equal to the name that the user typed in by passing it down from one react class to another
I can post more code but I thought props was the way to pass down code you needed elsewhere. this.state.value also returns undefined
edit:
myFunc called here:
<input type="submit" value="I can play" onClick={() => this.myFunc()}/>
thisinhandleChangemethod explicitly like thisthis.handleChange.bind(this). Try this and yes post more code if it still doesn't work, may be try Codepen to put your whole code on it.createClass. That would be a problem if the OP was using react components withclass.this.props.valueget set? Can you show the component that usesmyFunc?