I just started my first NextJS app and followed this guide to add MUI. The only difference I can see is that I'm using the experimental app
directory of NextJS 13.
When following the guide, I get a server error of Uncaught TypeError: React.createContext is not a function
which is basically rather clear, as the context API is only available to client components and can therefore rather easily be "solved" by placing the 'use client';
directory on top of the erroneous component.
Unfortunately it seems like this is required for every component which uses any part of MUI. E.g. I'd also have to 'use client;'
in my root layout.tsx
if I'd like to wrap my whole app with the ThemeProvider
etc.
My questions are the following:
- Do I really have to
'use client;'
everywhere I'd like to use MUI or is there some other way around? - If 1 is true: Doesn't this make MUI completely useless in combination with NextJS as it prevents the usage of all the SSR, SSG, ISR goodness etc or do I have some kind of misunderstanding here (I'm very new to NextJS in general...)?
- If 1 & 2 are true: Are there other recommendable UI frameworks or libraries which bring a good set of "ready to use" (and out of the box good looking) controls, components etc. that work better with NextJS without those limitations?
FYI, I have the following versions installed ATM:
next@13.0.6
@mui/material@5.10.17
Update
I should have read the NextJS beta docs more careful before posting the question:
It seams like there's no way around this ATM as stated here in the docs and again here in the a ticket.
So this answers question 1, as there doesn't seem to be a way around 'use client';
for now.
However, I'd still really appreciate answers and opinions on questions 2 & 3.