Skip to content

UseSwr being called twice, i have done everything but fetched is called twice #1952

@ceojazzy

Description

@ceojazzy

Bug report

Description / Observed Behavior

with simple next.js project i am suing useSwr in index.js and i saw that
console.log(data);
just after useSwr is called twice no matter what.

What kind of issues did you encounter with SWR?
data is being fetched twice.

Expected Behavior

It should be fetched once only.

How did you expect SWR to behave here?
twice calling?

Repro Steps / Code Example

_app.js
`
import "../styles/globals.css";
import "antd/dist/antd.css";
import { Layout, Menu, Breadcrumb } from "antd";
import Home from ".";
import MainMenu from "./navbars/main-menu";
const { Header, Content, Footer } = Layout;
import { QueryClient, QueryClientProvider } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
const queryClient = new QueryClient();

function MyApp({ Component, pageProps }) {
// return <Component {...pageProps} />
return (
Layout
Home
Layout
);
}

export default MyApp;

index.js
import Head from "next/head";
import Image from "next/image";
import styles from "../styles/Home.module.css";

import useSWR from "swr";
const fetcher = (url) => fetch(url).then((res) => res.json());
export default function Home() {
const { data, error } = useSWR("https://reqbin.com/echo/get/json", fetcher);

console.log(data);

return (


Done



);
}

`
Screenshot of issue:
image

Or share your code snippet or a CodeSandbox link is also appreciated!

Additional Context

SWR version.
Add any other context about the problem here.

"swr": "^1.3.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions