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

310
Views
ReactJs: How to get api data in child component with props?

I am trying to call api data only once thats way I call api in home.js file with componentdidmount in class component and i want to render this data in many child components with functional components.when i call api in every each child component,its work but when i try to call with props coming only empty array by console.log please help.

import React from 'react'
import '../styles/home.css'

import axios from 'axios';

import Teaser from './Teaser'
import Second from './Second'
import Opening from './Opening'
import Menu from './Menu'


export default class Home extends React.Component {
    state = {
      posts: []
    }
  
    componentDidMount() {
      
        axios.get("https://graph.instagram.com/me/media?fields=id,caption,media_url,permalink,username&access_token=IGQ")
        .then(res => {
          const posts = res.data.data;
          this.setState({ posts });
      
        })
    }
   
 
 

  render() {
    return (
      <>
       
       <Teaser/>
      
       <Second/>
       
       <Opening/>
    
      <Menu posts={this.state.posts}/>
         
      </>
    )
  }
}

import React from 'react'
import axios from 'axios';

function Menu(props) {

    const {posts} = props.posts;
    console.log(props);


    return (
        <>
        {posts.map(
          (post) =>
            post.caption.includes('#apegustosa_menu') &&
            post.children.data.map((x) => (
              <div className="menu_item" key={x.id}>
                <img className="menu_img" src={x.media_url} alt="image" />
              </div>
            )),
        )}
      </>

    )
}

export default Menu

about 4 years ago · Juan Pablo Isaza
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!