Answers for "access this from fetch react js"

3

React get method

/* React get method.  */

componentWillMount(){
    fetch('/getcurrencylist',
    {
        /*
        headers: {
          'Content-Type': 'application/json',
          'Accept':'application/json'
        },
        */
        method: "get",
        dataType: 'json',
    })
    .then((res) => res.json())
    .then((data) => {
      var currencyList = [];
      for(var i=0; i< data.length; i++){
        var currency = data[i];
        currencyList.push(currency);
      }
      console.log(currencyList);
      this.setState({currencyList})
      console.log(this.state.currencyList);
    })
    .catch(err => console.log(err))
  }
Posted by: Guest on July-21-2020
0

get data from url react

import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter, Route } from "react-router-dom";
const AppRouter = () => (
  <BrowserRouter>
    <Route path='/:parameter1/:parameter2/:parameter3' render={(props) => <App {...props} />} />
  </BrowserRouter>
);
const App = (props) => {
  const { parameter1, parameter2, parameter3 } = props.match.params;
  return (
    <div>
      First: {parameter1} <br />
      Second: {parameter2} <br />
      Third: {parameter3} <br />
    </div>
  );
};
ReactDOM.render(<AppRouter />, document.getElementById("root"));
Posted by: Guest on December-01-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language