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

126
Views
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 answers
Answer question

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 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!