Created
February 22, 2023 01:40
-
-
Save dcortesnet/ec2dcc3fb062d5faac598f932f36714c to your computer and use it in GitHub Desktop.
Nextjs solve hydrate error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "bootstrap/dist/css/bootstrap.min.css"; | |
| import "react-responsive-carousel/lib/styles/carousel.min.css"; | |
| import "slick-carousel/slick/slick.css"; | |
| import "slick-carousel/slick/slick-theme.css"; | |
| import "../styles/template.css"; | |
| import "../styles/responsive.css"; | |
| import "../styles/styles.css"; | |
| import { wrapper } from "../redux/store"; | |
| import { AppProps } from "next/app"; | |
| import { useEffect, useState } from "react"; | |
| import { Loader } from "@/components/Loader"; | |
| import Router from "next/router"; | |
| import { Provider } from "react-redux"; | |
| import { Layout } from "@/components/Layout"; | |
| function App({ Component, ...rest }: AppProps) { | |
| const { store, props } = wrapper.useWrappedStore(rest); | |
| const [loading, setLoading] = useState(false); | |
| const [domLoaded, setDomLoaded] = useState(false); | |
| useEffect(() => { | |
| const start = () => { | |
| setLoading(true); | |
| }; | |
| const end = () => { | |
| setLoading(false); | |
| }; | |
| Router.events.on("routeChangeStart", start); | |
| Router.events.on("routeChangeComplete", end); | |
| Router.events.on("routeChangeError", end); | |
| return () => { | |
| Router.events.off("routeChangeStart", start); | |
| Router.events.off("routeChangeComplete", end); | |
| Router.events.off("routeChangeError", end); | |
| }; | |
| }, []); | |
| useEffect(() => { | |
| setDomLoaded(true); | |
| }, []); | |
| return ( | |
| <> | |
| {loading ? ( | |
| <Loader></Loader> | |
| ) : ( | |
| domLoaded && ( | |
| <Provider store={store}> | |
| <Layout> | |
| <Component {...props.pageProps} /> | |
| </Layout> | |
| </Provider> | |
| ) | |
| )} | |
| </> | |
| ); | |
| } | |
| export default wrapper.withRedux(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment