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

307
Views
React-query / React-router dom issue

If I am using react-query and react-router, I can see the network requests happening when navigating, however the new data is not reflected in the view/page? Am I doing something wrong? I am doing lazy loading:

App.tsx

import React, { Suspense } from 'react';
import Loader from '../loader/Loader';

const App: React.FunctionComponent = () => {

  const Routing = React.lazy(() => import('../routing/Routing'));

  return (
    <>
      <Suspense fallback={<Loader />}>
        <DataProvider>
          <Routing />
        </DataProvider>
      </Suspense>
    </>
  );
}

export default App; 

router component:

import React from 'react';
import { BrowserRouter, Route, Switch} from 'react-router-dom';
import Header from '../header/Header';
import Component1 from './Component1';
import Compontent2 from './Component2';
import { QueryClient, QueryClientProvider } from 'react-query';
import { RouteComponentProps } from "react-router-dom";

const queryClient = new QueryClient()

const Routing: React.FunctionComponent = () => {

  return (
    <QueryClientProvider client={queryClient}>
    <BrowserRouter>
      <Header />
      <div className="App">
        <Switch>
          <Route exact path="/" component={Component1} />
          <Route path="/details/:id" render={(props: RouteComponentProps<any>) => <Component2 {...props}/>} />
        </Switch>
      </div>
    </BrowserRouter>
    </QueryClientProvider>
  )
}

export default Routing;

Component 1

const fetchAll = async () => {
        const res = await fetch('https:xxxxxx/xxxxx');
        return res.json();
    };

    const { data: result, status } = useQuery('info', fetchAll, {
        staleTime: 0,
    });

component 2 is using the same approach the react-query stuff is not in useEffect of anything?

How can I get the view to re-render on navigation and show the new data.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try and move the call to React.lazy outside of the fallback component?

 const Routing = React.lazy(() => import('../routing/Routing'));

const App: React.FunctionComponent = () => {
 return (
    <>
      <Suspense fallback={<Loader />}>
        <DataProvider>
          <Routing />
        </DataProvider>
      </Suspense>
    </>
  );
}

export default App; 

That's how they're using it in the official React docs here:

https://reactjs.org/docs/code-splitting.html

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