Answer the question
In order to leave comments, you need to log in
Where does the is not a function error come from?
There is a code:
class AddNewElement extends React.Component {
constructor (props) {
super(props);
this.state = {
input: ''
};
....
this.handleAddElement = this.handleAddElement.bind(this);
}
....
handleAddElement = (e) => {
e.preventDefault();
this.props.AddBrand(this.state.input);
}
render () {
return (
....
<button onClick={this.handleAddElement}>Добавить</button>
....
)
}
}
class Show extends React.Component {
constructor (props) {
super(props);
this.state = {
names: ["name1", "name2", "name3",]
};
}
AddBrand(name) {
this.setState((prevState) => ({ names: [...prevState.names, name] }));
}
render() {
return (
<div>
<ElementList names={this.state.names} AddBrand={this.AddBrand.bind(this)}/>
</div>
);
}
}
function ElementList({names, AddBrand}) {
return names.map((name) => (
<Element key={name} brand={name} AddBrand={AddBrand}/>
));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question