State Management · Junior · Question 37 of 75

How do you save a Zustand store to localStorage?

Explanation

create(persist((set) => ({...}), { name: 'cart' })) saves and restores the state. You can choose the storage, persist only some fields (partialize) and migrate old versions.

Further reading

Problem with a question

State Management · Junior · question 37

Test yourself

Take the State Management · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz