-
Notifications
You must be signed in to change notification settings - Fork 1.3k
UseSwr being called twice, i have done everything but fetched is called twice #1952
Description
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
);
}
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"
