简体   繁体   中英

Axios return [object Object] from an API request

I want to get data from an API, But when I log the data, it returns [ object Object]

 componentDidMount() {
  axios
   .get("https://jsonplaceholder.typicode.com/users")
   .then((response) => response.data
   )
   .then((users) => {
    this.setState({ Robots: users });
   });
 }

it gives me an Error when i try to filter the Robots object:

const filteredRobots = this.state.Robots.filter((robot) => {
   return robot.name
    .toLowerCase()
    .includes(this.props.SearchField.toLowerCase());
  });```

What do you need two.then for? That's probably where the object stops being an object.

componentDidMount() {
  axios
   .get("https://jsonplaceholder.typicode.com/users")
   .then((response) => {
     console.log(response.data)
     this.setState({ Robots: response.data })
   });
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM