Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Sending data from parent to child prop returns a value then undefined functional component

In the main dashboard component i do get requests for 5 arrays. When I log them into the console i get the data. When I try to pass down the data to a child component the values get undefined then values then undefined

The dashboard;

const [logdata, setLogData] = useState([])
const [storageData, setStorageData] = useState([])
const [logquotation, setLogQuotation] = useState([])
const [storageQuotation, setStorageQuotation] = useState([])
const [productQuotation, setProductQuotation] = useState([])

const getLogData = () => {
    axios.get("http://localhost:8080/api/logisticsrecords")
    .then(res => {
        setLogData(res.data)
        console.log(res)
    })
    .catch(err => console.log(err))
}

const getStorageData = () => {
    axios.get("http://localhost:8080/api/storageshipment")
    .then(res =>{
        setStorageData(res.data)
    })
    .catch(err => console.log(err))
}

const getLogisticsQuotation = () => {
    axios.get("http://localhost:8080/api/logisticsquotation")
    .then(res =>{
        setLogQuotation(res.data)
    })
    .catch(err => console.log(err))
}

const getStorageQuotation = () => {
    axios.get("http://localhost:8080/api/storagequotation")
    .then(res =>{
        setStorageQuotation(res.data)
    })
    .catch(err => console.log(err))
}

const getProductQuotation = () => {
    axios.get("http://localhost:8080/api/productquotation")
    .then(res =>{
        setProductQuotation(res.data)
    })
    .catch(err => console.log(err))
}


useEffect(() => {
    getLogData()
    getStorageData()
    getLogisticsQuotation()
    getProductQuotation()
    getStorageQuotation()
}, [])
console.log("dashboard data",logdata, storageData, storageQuotation, logquotation)

At this point when i log all the states to the console i get the values as expected. Passing the values as props to the child component

 <DashboardHome 
   storage={storageData} 
   logistics = {logdata}
   storeQuotation = {storageQuotation}
   prodQuotation = {productQuotation}
   logisticsQuotation = {logquotation}
    />

Destructuring the values at the child component

const DashboardHome = ({  storage,  logistics,  storeQuotation, prodQuotation, logisticsQuotation }) => {

console.log("The dashboard logistics/storage",storage, logistics)
console.log("the dashboard [quotation] data", storeQuotation, prodQuotation, logisticsQuotation)

console.log(storage, "storage data")
console.log("variable length is", storage)
return(...)}

What I get at the console enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda