Can I fetch data only once when using swr?

For example, I switch to different page using react router:

const Apage = () => {
    const { data, error } = useSWR('/a-data', fetcher);
    return (
        <div>{data}</div>
    );
};

const Bpage = () => {
    const { data, error } = useSWR('/b-data', fetcher);
    return (
        <div>{data}</div>
    );
};

With swr, I can get data immediately when I’m not the first time access the page.
But still, it calls the api to fetch data each time I access the page.

Can I only fetch data once if I dont need to revalidate the data is stale or not?

Leave a Comment