React - SetState, SetInterval and ComponetDidMount

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



React - SetState, SetInterval and ComponetDidMount



I'm very new to react and having an issue with the setState function based on a timer set in componentDidMount.



When the interval time sets, the function is called and I receive an error message that setState is not a method.



Here's my code, I've included only the necessary portion for brevity.



Note that my technical goal is to add a child component every second, my adding to a field in my state that is populating the component based on a map. If there's a better technique for that, I'd be interested.


class PanelDiv extends Component

constructor(props)
super(props);
this.state = items: [0];


render()

return (<div id="DivBackground" onLoad=() => this.PanelLoaded() style=width: '100%', height: '100%', backgroundImage: "url(" + BackgroundImage + ")", backgroundSize: "cover">

this.state.items.map((item) => (
<NumberButton/>
))

</div>);


componentDidMount()

setInterval(this.addChild, 1000);



addChild()


this.setState((previousState, currentProps) =>
console.log(previousState, currentProps)
return items: previousState.items.concat([0]);
);










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered