Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react axios POST with super constructor parent class

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: 'Reac Post Request Example'};
            axios.post('https://reqres.in/api/articles', article)
            .then( res => 
                this.setState({ articleId : res.data.id }));
            }
            
    render()
    {
        const {articleId} = this.state;
        return(
            <div className="card text-center m-3">
                <h5 className="card-header">Simple POST Request</h5>
                <div className="card-body">Returned Id: {articleId}</div> 
            </div>
         

        )
    }
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript destructure multiple levels 
Javascript :: using condition how to disable radio button in angular 
Javascript :: angular auth guard @medium 
Javascript :: new date is not working in react js 
Javascript :: Backbone Initialize vs Render 
Javascript :: javascript foreach next item 
Javascript :: Mirror Inverse Program in javascript 
Javascript :: map function usage in frontend 
Javascript :: hsv to rgb js 
Javascript :: Quick JS DATE 
Javascript :: moment format time 
Javascript :: facebook access token 
Javascript :: regex remove whitespace 
Javascript :: Minimum Path Sum Rec 
Javascript :: Nested Components 
Javascript :: react js date range 
Javascript :: move_uploaded_file equivalent in js 
Javascript :: Could not resolve dependency: npm ERR! peer react@"^16.0.0" from react-acceptjs@0.1.2 
Javascript :: javascript detect if active element is writable 
Javascript :: javascript$.4908BEAMpacidE 
Javascript :: creating a react app from scratch 
Javascript :: javascript declaring variables 
Javascript :: traversing 2d array javascript 
Javascript :: js draw number in range 
Javascript :: for (i = 0; i < N; i++) for (j = 0; j < N; j++) { .... some O(1) code ... } 
Javascript :: parcel react 
Javascript :: Randomly getting error 500 in Azure App Service when downloading angularjs template 
Javascript :: Popover AngularJs quickly disappearing 
Javascript :: I am getting an error "createSpyObj requires a non-empty array" with running unit tests, which were executed perfectly before 
Javascript :: What is the best way to download mulitple images using jquery 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =