-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
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
Support for next.js #204
Comments
@ajayjaggi97 I've tried for the last 3 days to get it to work with next.js and I'm finally happy to use it. This is where the magic happens: Here is the content of my _app.tsx: export default function MyApp({ }: AppProps) {
const styles: string[] = useMemo(() => [], []);
const addStyles = useCallback(
(...newStyles) => {
if (typeof document === 'undefined') {
styles.push(...newStyles.map((s) => s._getCss()));
} else {
newStyles.forEach((s) => s._insertCss());
}
},
[styles]
);
return (
<>
<StyleProvider value={{ insertCss: addStyles }}>
<ColorInput />
</StyleProvider>
<StyleRenderer styles={styles} />
</>
);
} and my StyleRenderer.tsx: export type StyleRendererProps = { styles: string[] };
export function StyleRenderer({ styles }: StyleRendererProps) {
return (
<Head>
<style>{styles.join()}</style>
</Head>
);
} Note that I use And also note that I did not use |
Hey @Ainias .Thanks for the solution. I had the similar use case where we had a components library. |
Do you have a specific example for reference? thank you |
@Ainias @ajayjaggi97 can you give a example? I'm very curious about how to actually implement this🤪. |
Can you pls share the insights of using isomorphic-style-loader with next.js. How can we pass the required context value of insertCss??
The text was updated successfully, but these errors were encountered: