Answer the question
In order to leave comments, you need to log in
Optional props passing to react?
Let's say there is some form, and in it the fields
<Input onNameChange={this.props.onNameChange} title={"Name"} type={'text'}/>
<Input title={"Surname"} type={'text'}/>
<label>
<p>{this.props.title}</p>
<input onChange={this.handleChange} type={this.props.type}/>
</label>
Answer the question
In order to leave comments, you need to log in
onChange =(name)=> this.props.onNameChange && this.props.onNameChange(name)
You need to be onChange
in андефайнд
.
In a functional component, this problem does not even arise:
const Input = ({ title, type, onNameChange }) => (
<label>
<p>{title}</p>
<input onChange={onNameChange} type={type} />
</label>
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question