import React, { Component } from "react"; import axios from "axios"; export default class Dashboard extends Component { state = { users: [] }; componentDidMount () { this.GetUsers(); } GetUsers(AppState) { axios .get("https://jsonplaceholder.typicode.com/users") .then(res => { this.setState({users: res.data}); console.log("users", res.data); }) .catch(function(error) {}); } render() { console.log("users", this.state.users); console.log("users state", this.state.users[0]); return ( <div className="App"> <h1>Hello CodeSandbox</h1> </div> ); } }
Обсуждают сегодня