I have the following class component:
class ConceptPopup extends React.Component {
constructor(props) {
super(props);
this.state = {
attributeForm: []
};
this.addAttributeForm();
}
addAttributeForm() {
//this method adds label and input field to the state array
var array = this.state.attributeForm;
array.push(<div>
<span><b>new Attribute</b></span>
<div>
<label htmlFor="name">Attribute name :</label>
<input name="name"/>
</div>
</div>
);
this.setState({
attributeForm: array
});
}
render() {
return (
<div>
{this.state.attributeForm}
<button onClick={this.addAttributeForm.bind(this)}>ADD ATTRIBUTE</button>
</div>
);
}
}
Now the ideal situation would be that everytime the ADD ATTRIBUTE button is clicked a new input field appears.
My current situation is that the method addAttribute is called on button click and the state updates correctly but the changes aren't visible. All that is shown is one input field due to the addAttributeForm from the constructor. I tried to force re-render the form on click but that only throws a buch of errors (like Maximum call stack size exceeded).