JS.React. Wow! SetState is async )

The discussion is here.

In my code i did like this to get the proper result of the state

    setMyName(myName, f) {
        this.setState({myName}, () => {
            f()
        });
    }
...
handleImgClick = (e) => {
        this.setMyName('Stanley', () => {alert(this.state.myName)});
    }

This entry was posted in Без рубрики. Bookmark the permalink.