We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useTheme
useTheme nextjs
use useTheme from ../zero-styled to let Pigment CSS process.
../zero-styled
Got error at build time:
As I dug deeper, I found that Next.js wraps the component before passing to Pigment like the snippet below:
const Component = /*#__PURE__*/_s(React.forwardRef(_c = _s(function Component(inProps, ref) { _s(); const props = useThemeProps({ props: inProps, name: "MuiIconButton" }); return … }, "526RDEpO1CGEADq5vnCvoNyCejQ=", false, function () { return [useThemeProps, useTheme, useUtilityClasses]; })), "526RDEpO1CGEADq5vnCvoNyCejQ=", false, function () { return [useThemeProps, useTheme, useUtilityClasses]; });
Since Pigment replaces useTheme with a variable, I think that's why useTheme is no longer available when Next.js before building the page at the end.
The page should be rendered without any error.
I am trying to use useTheme processor in mui/material-ui#42476
npx @mui/envinfo
Don't forget to mention which browser you used. Output from `npx @mui/envinfo` goes here.
The text was updated successfully, but these errors were encountered:
@brijeshb42 I believe that useTheme should be changed to createUseTheme (we can add internal_ prefix to it) and update the runtime createUseTheme:
createUseTheme
internal_
// runtime createUseTheme import theme from '@pigment-css/react/theme'; export default function createUseTheme() { return function useTheme() { return theme; } }
So that Pigment does not replace the useTheme in the consumer codebase:
import { createUseTheme } from '../zero-styled'; const useTheme = createUseTheme(); function Component() { const theme = useTheme(); }
Sorry, something went wrong.
stringifyTheme
@siriwatknp Is there a PR/branch to test the useTheme changes in material-ui ? I wanted to test few approaches.
Is there a PR/branch to test the useTheme changes in material-ui ? I wanted to test few approaches
You can test it at mui/material-ui#42476 using the apps/pigment-nextjs-app.
apps/pigment-nextjs-app
FYI, I tried with this but does not work too:
// mui-material/src/Tooltip import { useTheme } from '../zero-styled'; const useLocalTheme = () => useTheme(); … function Tooltip() { const theme = useLocalTheme(); }
Nextjs wraps the useLocalTheme with useTheme dependencies too and since useTheme is replaced by Pigment, Nextjs throw the same error.
useLocalTheme
brijeshb42
Successfully merging a pull request may close this issue.
Search keywords
useTheme nextjs
Latest version
Steps to reproduce
use
useTheme
from../zero-styled
to let Pigment CSS process.Current behavior
Got error at build time:
As I dug deeper, I found that Next.js wraps the component before passing to Pigment like the snippet below:
Since Pigment replaces
useTheme
with a variable, I think that's whyuseTheme
is no longer available when Next.js before building the page at the end.Expected behavior
The page should be rendered without any error.
Context
I am trying to use
useTheme
processor in mui/material-ui#42476Your environment
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: