{"id":8604,"date":"2023-08-29T04:59:23","date_gmt":"2023-08-29T04:59:23","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=8604"},"modified":"2023-08-29T04:59:23","modified_gmt":"2023-08-29T04:59:23","slug":"react-hydration-error-in-nextjs","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react\/react-hydration-error-in-nextjs","title":{"rendered":"How to Solve React Hydration Error in Nextjs"},"content":{"rendered":"<p>This error occurs when there is a mismatch of pre-rendered HTML from server and the first render of the browser.<\/p>\n<p>This can be caused by one of the followings:<\/p>\n<ul>\n<li>Incorrect nesting of HTML tags,<\/li>\n<li>using checks like typeof window !== &#8216;undefined&#8217; in logic,<\/li>\n<li>using browser-only APIs like window\/localStorage in logic,<\/li>\n<li>incorrectly configured CSS-in-JS libraries etc.<\/li>\n<\/ul>\n<p>We can implement following solutions depending on use-case:<\/p>\n<ol>\n<li>Using useEffect to run on the client only<\/li>\n<li>Disabling SSR on specific components<\/li>\n<li>Using suppressHydrationWarning<\/li>\n<\/ol>\n<p>There is a dedicated information page on official site of <a href=\"https:\/\/nextjs.org\/docs\/messages\/react-hydration-error\" target=\"_blank\" rel=\"noopener\">Next.js<\/a> for this error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This error occurs when there is a mismatch of pre-rendered HTML from server and the first render of the browser. This can be caused by one of the followings: Incorrect nesting of HTML tags, using checks like typeof window !== &#8216;undefined&#8217; in logic, using browser-only APIs like window\/localStorage in logic, incorrectly configured CSS-in-JS libraries etc. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8605,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8604","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8604"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=8604"}],"version-history":[{"count":3,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8604\/revisions"}],"predecessor-version":[{"id":8608,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8604\/revisions\/8608"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/8605"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=8604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=8604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=8604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}