현인

[warning] Please update your code: use createWrapper() and wrapper.useWrappedStore() 본문

개발 일기

[warning] Please update your code: use createWrapper() and wrapper.useWrappedStore()

현인(Hyeon In) 2023. 5. 2. 10:42

기존 코드

import type { AppProps } from "next/app";
import { ThemeProvider } from "next-themes";
import wrapper from "@/store/configureStore";

// React-Query
import { ReactQueryDevtools } from "react-query/devtools";
import { QueryClient, QueryClientProvider } from "react-query";

import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import "@/styles/globals.scss";

const client = new QueryClient({
  defaultOptions: {
    queries: {
      // React-Query 옵션 설정
    },
  },
});

function App({ Component, pageProps }: AppProps) {
  return (
    <ThemeProvider attribute="class">
      <QueryClientProvider client={client}>
        <Component {...pageProps} />
        <ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
      </QueryClientProvider>
    </ThemeProvider>
  );
}

export default wrapper.withRedux(App);

 

마지막 줄에 wrapper.withRedux(App); 부분이 legacy한 표현이라는 경고 문구가 떠서 공식 문서를 확인해보니 사용법이 바뀌었다.

수정된 코드

import type { AppProps } from "next/app";
import { ThemeProvider } from "next-themes";
import wrapper from "@/store/configureStore";

// React-Query
import { ReactQueryDevtools } from "react-query/devtools";
import { QueryClient, QueryClientProvider } from "react-query";

import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";
import "@/styles/globals.scss";
import { Provider } from "react-redux";

const client = new QueryClient({
  defaultOptions: {
    queries: {
      // React-Query 옵션 설정
    },
  },
});

function App({ Component, ...rest }: AppProps) {
  const { store, props } = wrapper.useWrappedStore(rest);
  return (
    <ThemeProvider attribute="class">
      <Provider store={store}>
        <QueryClientProvider client={client}>
          <Component {...props.pageProps} />
          <ReactQueryDevtools initialIsOpen={false} position="bottom-right" />
        </QueryClientProvider>
      </Provider>
    </ThemeProvider>
  );
}

export default App;

 

참고

- https://github.com/kirill-konshin/next-redux-wrapper#redux-toolkit

 

GitHub - kirill-konshin/next-redux-wrapper: Redux wrapper for Next.js

Redux wrapper for Next.js. Contribute to kirill-konshin/next-redux-wrapper development by creating an account on GitHub.

github.com

 

반응형