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

249
Visualizações
Can't access the data in the redux state object

I am facing an issue while rendering a dynamic page in NEXT.JS. While clicking on a list-item DOES redirect me to the detail-page, the data in the detail page is still not available.

I am fetching the poData in the detail-page, and if i try to log it in console, it works perfectly and logs out all the keys inside it.

However, when i try to render the individual keys in poData, for example poData.refId, an error is thrown saying that can't read refId of undefined. (line 30)

(refId is also the pageId used in redirection which proves the data is valid) This doesn't make sense bcz in line 29 the poData is logged on screen and doesn't throw the error.

Also, if i just log the poData without trying to access the nested data in the object, i am able to see the object containing all the nested data when it is logged on screen.

Redux Slice Code:

import { createSlice } from "@reduxjs/toolkit";
import purchaseOrdersDb from '../../db/purchaseOrders'

const initialState = [
];

const poSlice = createSlice({
  name: "po",
  initialState,
  reducers: {

    addPO(state, action) {
      // Check PO List for duplicates
      const duplicateIndex = state.findIndex(el => el.refId === action.payload.refId)
      // Add the new PO
      duplicateIndex < 0 ? state.push(action.payload) : console.log(`Duplicate Found`);;
    },

  },
});

export const poActions = poSlice.actions;
export default poSlice;

Component Code:

/* Next Functions */
export async function getStaticPaths() {
  return {
    paths: [
      { params: { refId: '1' } }
    ],
    fallback: 'blocking'
  }
}

export async function getStaticProps(context) {
  const pid = context.params.refId;
  return {
    props: {
      pid
    }
  }
}

/* Page Component Function */
export default function POdetail(props) {

  const poData = useSelector(state => { return state.po.find(item => item.refId === props.pid) })

  poData && console.log(poData);
  poData.refId && console.log(poData.refId);

  return (
    <>
      <h1>{poData.refId} </h1>
    </>
  )
}

The screen shot of the error Code Screenshot of the dynami Code Screenshot of the relevant redux slice

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