Search
 
SCRIPT & CODE EXAMPLE
 

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>
         

        )
    }
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: remove substring from string liquid shopify 
Javascript :: javascript caeser cipher 
Javascript :: add line number in javascript 
Javascript :: mongoose connection increase timeout in node js 
Javascript :: put logo in qr code in react js qrcode.react 
Javascript :: react native flatlist container style 
Javascript :: convert string to integer in javascript 
Javascript :: js setinterval vs settimeout 
Javascript :: vue dynamic routes with parameters 
Javascript :: javascript loop an array check if a number is even 
Javascript :: expo modal 
Javascript :: text background fabricjs 
Javascript :: email validation node js 
Javascript :: get role id from role position 
Javascript :: Learn how to use Js export and import. 
Javascript :: collapse in angular 4 
Javascript :: %PDF-1.4 is response 
Javascript :: timing code in javascript 
Javascript :: validation in react native 
Javascript :: js copy text 
Javascript :: javascript perform click 
Javascript :: null data type in javascript 
Javascript :: to higher case js 
Javascript :: check the number is palindrome or not 
Javascript :: create array of numbers js 
Javascript :: get max value of slider js 
Javascript :: timestamp to date 
Javascript :: useEffect : react 
Javascript :: how to run socket.io server 
Javascript :: filereader reactjs 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =