-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Server rendering with Next.js #462
Comments
Sidenote: import { View, Text, StyleSheet } from 'react-native';
export default () =>
<View style={{ backgroundColor: 'blue' }}>
<Text style={{ fontFamily: 'Comic Sans MS'}}>
testing
</Text>
</View> The server-rendered version doesn't have a blue background. But it does if I set Is this intended behaviour? |
Server-rendering guide: https://github.com/necolas/react-native-web/blob/master/docs/guides/getting-started.md#server-side-rendering If there's an issue with the server-rendering styles, please open a separate issue with steps to reproduce. Thanks |
Not sure how I missed that. Thanks Nicolas! |
Here's my solution below for anyone looking to integrate with Next.js, or if anyone has a better solution to propose: pages/_document.js: import Document, { Head, Main, NextScript } from 'next/document'
import { AppRegistry } from 'react-native-web';
export default class MyDocument extends Document {
static async getInitialProps ({ renderPage }) {
AppRegistry.registerComponent('Main', () => Main);
const { stylesheet } = AppRegistry.getApplication('Main');
const page = renderPage();
const styles = <style dangerouslySetInnerHTML={{ __html: stylesheet }} />;
return { ...page, styles };
}
render () {
return (
<html>
<Head>
<title>My page</title>
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
} |
FYI, We could add an example to the Next.js repo |
I've added a react-native-web example to the Next.js repository. |
May I ask how will you make |
@dcalhoun This is working well for inline styles and styles generated with the StyleSheet api, but I'm using classes and that doesn't seem to work. |
👋🏻 @Gregoirevda. This issue is very old. Also, it has been a while since I worked with Next.js and React Native for Web. I recommend opening a new discussion in this project seeking help. Doing so is more likely to gain visibility and assistance from the maintainers or others. Hope this helps. 🙇🏻♂️ |
Hey, I've managed to get things running with Next.js, but it seems server rendering doesn't include CSS.
Is there an API to grab the CSS for the page when server rendering? Like in this example with styled-components: https://github.com/zeit/next.js/blob/master/examples/with-styled-components/pages/_document.js
Thanks!
The text was updated successfully, but these errors were encountered: