Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
RTK Query returns partial data when receiving URL param from Redux state

I'm looking to pass an ID value successfully stored in Redux state to a RTK Query, for dynamic fetching behaviour.

However, when I pass the state object through, I only receive a partial response of an array of varying lengths (sometimes no objects, sometimes two, very occasionally the whole response).

src/features/api/apiPayrollEntries.ts

// READ All Payroll Entries by Payroll ID
getAllPayrollEntriesByPayrollId: builder.query<PayrollEntry[], string>({
  query: (payrollId) => `/payroll-entries/payroll/${payrollId}`,
  providesTags: ["PayrollEntry"],
}),

PayrollEntries.tsx

const PayrollEntries: FC = () => {
  const provisionedPayrollId: string = useAppSelector(
    (state: any) => state.provisionedPayroll.id
  );

  const { data: dataPayrollPayrollEntries } =
    useGetAllPayrollEntriesByPayrollIdQuery(provisionedPayrollId);

  console.log(provisionedPayrollId);
  // => "ed7c6cc9-8835-4974-ac0d-4cf54e917898"

  console.log(dataPayrollPayrollEntries);
  // => returns array of varying (0-all) results

  // const { data: dataPayrollPayrollEntries } =
  // useGetAllPayrollEntriesByPayrollIdQuery(
  //   "ed7c6cc9-8835-4974-ac0d-4cf54e917898"
  // );
  // => reliably returns all results
}

I intuit there's some sort of timeout issue between fetching from state and calling/completing the query, but I can't find a pattern to overcome this. I have also tried implementing useEffect() to ensure the state's ID value was available, but to no success.

I've reviewed Constructing a Dynamic Base URL Using Redux State but am not certain if this is the right approach? Any support in clarifying my understanding is appreciated. Thanks in advance.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I resolved this by understanding that my frontend was racing ahead of the process completing server-side. Hence the partial return of date -- the server was returning only the data available at the time of the frontend request.

I resolved by passing a "complete" object to the frontend to enable action of the frontend router redirect.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda