Close
React

What is Promise in React JS?

What is Promise in React JS?

class PromiseExample extends Component {
state = {
data: null,
error: null,
loading: true,
};

componentDidMount() {
fetchData()
.then(result => {
this.setState({ data: result, loading: false });
})
.catch(error => {
this.setState({ error: error.message, loading: false });
});
}

Leave a Reply

Your email address will not be published. Required fields are marked *