I'm getting an error of "Cannot read props of undefined" when passing an onchange function to a child component, however, when console logging the props, the correct properties show up.
I did this previously where I passed an onClick prop to a child button, and that seems to have worked fine.
The error message only happens when attempting to edit the field.
Parent component
//Parent component
onChange = e => {
e.preventDefault();
console.log(e);
}
render(){
return(
<div className="App">
<div className="cardRow">
<Card question={this.state.currentCard.question}
answer={this.state.currentCard.answer}
source={this.state.currentCard.source}
onClick={this.submitUpdate.bind(this)}
recordChange={this.onChange.bind(this)}>{this.state.update}</Card>
.....
//child component
class Card extends Component {
//the below code is where the error message is pointing
recordChange(){
this.props.recordChange();
}
onSubmit(){
this.props.onSubmit();
}
render(props){
console.log(this.props);
return(
<div className="card-container">
{this.props.children?
<div className="cardUpdate">
<form className="update-form">
<h5>Front</h5>
<input type="text"
value={this.props.question}
onChange={this.recordChange}/>
<h5>Answer</h5>
<textarea type="text"
value={this.props.answer}
onChange={this.recordChange}/>
<h5>Source</h5>
<input type="text"
value={this.props.source}
onChange={this.recordChange}/>
<div>
<button onClick={this.props.onClick}>Submit</button>
</div>
</form>
</div>
:
<div className="card">
<div className="front">
<div className="question">{this.props.question}</div>
</div>
<div className="back">
<div className="answer">{this.props.answer}</div>
<div className="source">{this.props.source}</div>
</div>
</div>
}
</div>
);
}