Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react axios POST using async await method with super constructor parent class

export default class PersonList extends React.Component {
    constructor(props) {
        super(props)
    this.state = {
       articleId: null
            };
                }
   async componentDidMount() {
        const article = {title: 'Reac Post Request Example'};
            const res = await axios.post('https://reqres.in/api/articles', article);
       
                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>
         

        )
    }
}

 
PREVIOUS NEXT
Tagged: #react #axios #POST #async #await #method #super #constructor #parent #class
ADD COMMENT
Topic
Name
4+6 =