---
title: "Discussion on \"How to use Zustand's persist middleware in Next.js\" | Hashnode"
description: "Discussion on \"How to use Zustand's persist middleware in Next.js\". Solving the hydration error occurring with Zustand's persist middleware in Next.js"
url: "https://hashnode.com/posts/how-to-use-zustands-persist-middleware-in-nextjs/640f4e685c1c3f8f90cb3705"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to use Zustand's persist middleware in Next.js](https://blog.abdulsamad.dev/how-to-use-zustands-persist-middleware-in-nextjs?utm_source=hashnode&utm_medium=feed)

Solving the hydration error occurring with Zustand's persist middleware in Next.js

Mar 13, 2023 · 3 min read · blog.abdulsamad.dev  
Updated Mar 30, 2023  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#nextjs](https://hashnode.com/tag/nextjs)
-   [#state-management](https://hashnode.com/tag/state-management)
-   [#error](https://hashnode.com/tag/error)

## Written by

[Abdul Samad Ansari](https://hashnode.com/@abdulsamad-ansari)

@abdulsamad-ansari · Mumbai, India

  
[View profile](https://hashnode.com/@abdulsamad-ansari)

I love crafting engaging web experiences and building reliable software

Web Developer and lifelong learner currently focused on Full stack MERN development. Skilled in HTML, CSS, JavaScript (ES5 and Up), React, TypeScript, Node, and MongoDB. Looking to expand my horizons in Web Development and Technology.

## Responses 1

Markdown supported · ⌘↵ to post

[Simo D.](https://hashnode.com/@simoooo)

[Oct 14, 2023](https://hashnode.com/posts/how-to-use-zustands-persist-middleware-in-nextjs/640f4e685c1c3f8f90cb3705/comment/652b1d7e900df10a39260e2e)

I tried this method but it caused my page to fall in a infinite loop due to the useEffect hook re-rendering the page every time the result variable changes and that same variable in used to set the state. any solution to this problem?

[Abdul Samad Ansari](https://hashnode.com/@abdulsamad-ansari)

[Oct 22, 2023](https://hashnode.com/posts/how-to-use-zustands-persist-middleware-in-nextjs/640f4e685c1c3f8f90cb3705/comment/652b1d7e900df10a39260e2e#reply-6534dd88aa602055e82fd9b7)

Hi Simo, The hook initially gives null and after that, the state is updated. I'm not sure why you're facing this problem. Please check the useEffect dependencies.
