-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Error in Documentation for _document.tsx #441
Comments
Hey @anoushk1234 I don't think it's a issue with NextUI. My solution is to use Reference: vercel/next.js#36008 (comment) Example: https://codesandbox.io/s/next-ui-ts-bf0t1z import { Children } from "react";
import { CssBaseline } from "@nextui-org/react";
import Document, { Html, Main, Head, NextScript } from "next/document";
const MyDocument = () => {
return (
<Html>
<Head>{CssBaseline.flush()}</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
};
MyDocument.getInitialProps = async (context) => {
const initialProps = await Document.getInitialProps(context);
return {
...initialProps,
styles: [ ...Children.toArray(initialProps.styles) ]
};
}; |
hey, if it's not an issue with the defined types then the documentation needs to be update because |
Hey @anoushk1234 could you please share with us your |
Yes sure, here you go https://github.com/anoushk1234/anoushk.xyz/blob/main/tsconfig.json |
Here's how I fixed it: import Document, { Html, Head, Main, NextScript } from "next/document";
import { CssBaseline } from "@nextui-org/react";
class MyDocument extends Document {
static async getInitialProps(ctx: any) {
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: [<>{initialProps.styles}</>],
};
}
render() {
return (
<Html lang="en">
<Head>{CssBaseline.flush()}</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument; |
ohk got it, I'll update the docs with this code |
This doesn't work for me. React throws a warning for duplicate keys when using an array. I'm ignore ts typechecking at the moment. |
Describe the bug
heres the code from the docs
i get a type error at this line
styles: <>{initialProps.styles}</>,
sayingType 'Element' is not assignable to type 'ReactElement<any, string | JSXElementConstructor<any>>[] | ReactFragment | undefined'
if i remove the <> </> it doesnt show a type error and it works
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
Follow the nextjs guide in the docs https://nextui.org/docs/guide/getting-started#nextjs
Expected behavior
the documentation should have the correct code
Screenshots or Videos
No response
Operating System Version
macOS
Browser
Firefox
The text was updated successfully, but these errors were encountered: