I want to be able to generate a certain number of components (all similar) according to a value chosen in a select element.
I tried to generate this by creating an array of components whose size is the selected number. When I select a number it launch a handle function which changes the selected number in the creation.
handle = selected => {
this.state.number= selected.value;
this.forceUpdate();
};
render() {
return(
<Select onChange={this.handle} options = { ... }/>
{[...Array(this.state.number)].map(e => { return ( <TestComponent />
); })}
)
}
It loads the first component because the number is initialized to 1 but when I select another number 2,3,4,5,... it doesn't render the new components.