Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
múltiples llamadas API en un componenteDidMount usando Axios en reaccionar

Aquí está mi código React js para una sola llamada API para un selector de rango de fechas. ahora quiero llamar a varias API en React con el método componentDidMount, ¿es posible? Si es así, ¿cómo puedo hacerlo?

 import React,{ Component} from "react"; import axios from 'axios' class PostList extends Component{ constructor(props) { super(props) this.state = { posts: [] } } componentDidMount(){ axios.get('http://127.0.0.1:8000/betweendays') .then(response => { this.setState({ posts:response.data }) console.log(response.data) }) } render() { const {posts} = this.state return ( <div> <h1>get call in React js</h1> { posts.map(post => <div key = {post.id}>{post.id} </div>) } </div> ) } } export default PostList```
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Usando el método .then() para crear una cadena de solicitudes.

 componentDidMount() { axios.get('http://127.0.0.1:8000/betweendays') .then(response => { this.setState({ posts: response.data }) return response.data; // returning response }) .then(res => { // do another request Note we have the result from the above // getting response returned before console.log(res); }) // Tag on .then here .catch(error => console.log(error)) }
about 4 years ago · Juan Pablo Isaza Report

0

Puede agregar más apis en componentDidMount como desee.

 componentDidMount(){ axios.get('http://127.0.0.1:8000/betweendays') .then(response => { this.setState({ posts:response.data }) console.log(response.data) }) axios.get('link') .then(response => { this.setState({ posts:response.data }) console.log(response.data) }) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!