I'm trying to use React-Select V2.0 with Next.JS but on server load the select element is not styled and flickers to styled.
I tried using the Emotion example for Next.JS to server render the emotion style (https://github.com/zeit/next.js/tree/master/examples/with-emotion) but it seem to conflict with Styled-JSX which I use and I get the error StyleSheet: insertRule accepts only strings.
I tried using the Emotion babel config options shown here: https://github.com/emotion-js/emotion/blob/master/docs/configurable-imports.md#babel-options
but that causes the whole page to be rendered not styled and then flickers to styled.
Does anyone know how to use React-Select V2 on Next.JS with server rendering?
Thanks.
Similar to other answers here, the only way I could get this working was to use a dynamic import. I would encourage you to provide some sort of loading indicator.
const ReactSelectNoSSR = dynamic(() => import('../components/select'), {
loading: () => <Input />,
ssr: false
});
If you need to test this component with Jest, here's how you would do that. Hope this helps.
A solution to the flickering render with React-Select v2.0 with Next.js is to render the component in client-side only using react-no-ssr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With