Skip to content Skip to sidebar Skip to footer

How To Use Variable In React Js

import React from 'react' import { Link } from 'react-router' var result;var response;var jsonString ;var msg; var xhr = new XMLHttpRequest(); var xhrPost = new XMLHttpRequest();

Solution 1:

First - use some labriry like fetch, to create some ajax requests.

Second - if you want to create it by yourself use Promise to create async operations:

returnnewPromise((resolve) => {
    //perform some async actionsresolve(result)
})

Then in components:

fetchData().then((result) =>this.setState({msg: result})

Post a Comment for "How To Use Variable In React Js"