Wednesday, December 1, 2021

async in react.js




All react JS is asynchronous.

it provides a declarative API to perform any REST API calls using a single React component 

Example

     componentDidMount() {
        this.getData();
    }
    async getData() {
      this.setState({loading: true});
        axios
            .get("/access_control/access/getAll")
            .then(response => {
                this.setState({
                    data: response.data,
                    loading: false
                })
            })
            .catch(error => {
                console.error(
                    'There has been a probelm with an axios operation:',
                    error
                );
                this.setState({ifSuccess: false, msg: 'There has been a probelm with retriving module list.', loading: false});
            });
    }

No comments:

Post a Comment