Last active
February 20, 2024 23:57
-
-
Save filiptdz/974aeeb6a52254fc13128a36cdadb226 to your computer and use it in GitHub Desktop.
react-native-web SSR Setup for NextJS using app router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SSRStylesWrapper from './SSRStylesWrapper'; | |
export default function RootLayout({ | |
children | |
}: { | |
children: React.ReactNode; | |
}) { | |
return ( | |
<html lang="en"> | |
<body> | |
<SSRStylesWrapper>{children}</SSRStylesWrapper> | |
</body> | |
</html> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use client'; | |
import { createElement, PropsWithChildren } from 'react'; | |
import { useServerInsertedHTML } from 'next/navigation'; | |
import { StyleSheet } from 'react-native'; | |
const SSRStylesWrapper = ({ children }: PropsWithChildren<{}>) => { | |
useServerInsertedHTML(() => { | |
return createElement('style', { | |
dangerouslySetInnerHTML: { | |
// @ts-expect-error | |
__html: StyleSheet.getSheet().textContent | |
} | |
}); | |
}); | |
return children; | |
}; | |
export default SSRStylesWrapper; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another option for the SSRStylesWrapper: