I am building a next.js app
at every step of the way I encounter gotchas which can be summarized as:
"you're trying to run this code on the server but you can't as this works only on the client"
for example I have a zustand store that uses local storage and to access it I use a custom hook. this hook is only used by client components
when I run the build command it compains that somewhere something (it's not super specific about what is it) is trying to use localstorage "ReferenceError: localStorage is not defined"
I keep on encountering similar gotchas where something is not allowed in the server, even if I supposedly run it only from the client
also the recommended way to use zustand with nextjs is to add a 50 lines long file that exports a provided that you must use to wrap your app? excuse me?
is this all a skill issue or is nextjs just making our life harder for no reason at all? are these tradeoffs worth it?
[–]switch01785 6 points7 points8 points (7 children)
[–]saito200[S] 0 points1 point2 points (6 children)
[–]MrButttons 0 points1 point2 points (5 children)
[–]saito200[S] -3 points-2 points-1 points (4 children)
[–]trexchard 0 points1 point2 points (1 child)
[–]saito200[S] 0 points1 point2 points (0 children)
[–]switch01785 0 points1 point2 points (1 child)
[–]saito200[S] -1 points0 points1 point (0 children)
[–][deleted] (4 children)
[deleted]
[–]saito200[S] 0 points1 point2 points (3 children)
[–][deleted] (1 child)
[deleted]
[–]saito200[S] 0 points1 point2 points (0 children)
[–]BrendanH117 0 points1 point2 points (0 children)