Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react POST ERROR HANDLING

import React from 'react';
 import './App.css';
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.min.css';

export default class PersonList extends React.Component {
    constructor(props) {
        super(props)
    this.state = {
       articleId: null
            };
                }
  componentDidMount() {
        const article = {title: 'ReacT Post Request Example'};
           axios.post('https://reqres.in/invalid-url', article)
           .then(res => this.setState({articleId: res.data.id} ))
           .catch(error => {
            this.setState({errorMessage: error.message});
            console.error('This is an Error!', error);
           });

       
  }
    render()
    {
        const {errorMessage} = this.state;
        return(
            <div className="card text-center m-3">
                <h5 className="card-header">Simple POST Request</h5>
                <div className="card-body">Error : {errorMessage}</div> 
            </div>
         

        )
    }
}

 
PREVIOUS NEXT
Tagged: #react #POST #ERROR #HANDLING
ADD COMMENT
Topic
Name
4+9 =