1

I can't reach the data.

MyApi.js

fetch('https://reqres.in/api/users?page=2')
.then(res => res.json())
.then((result) => {
UsersAPI.users.push(result.data)
});

const UsersAPI = {
 users: [],
};

export default UsersAPI;

MyUsers.js

 export default class MyUsers extends Component {
  render() {
    console.log(UsersAPI.users);
    return (
          <div></div>
    ) ....

Console

console.log( UsersAPI.users[0] ) not working. How can I show data in the console. If my code is wrong you can make changes to my code

tom clarck
  • 103
  • 1
  • 8
  • You can’t rely on the timing of the data becoming available without explicitly chaining on the promise’s `.then`. – deceze Dec 31 '18 at 11:12

0 Answers0