简体   繁体   English

React-Select V2.0 with Next.JS

[英]React-Select V2.0 with Next.JS

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. 我正在尝试将React-Select V2.0与Next.JS一起使用,但在服务器加载时,select元素没有样式并且闪烁样式。

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. 我尝试使用Next.JS的Emotion示例来服务器呈现情感样式( https://github.com/zeit/next.js/tree/master/examples/with-emotion )但它似乎与Styled-JSX冲突我使用的,我得到错误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 我尝试使用此处显示的Emotion babel配置选项: 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? 有谁知道如何在服务器渲染的Next.JS上使用React-Select V2?

Thanks. 谢谢。

使用带有Next.js的React-Select v2.0进行闪烁渲染的解决方案是仅使用react-no-ssr在客户端渲染组件

I currently use Next.js dynamic component loading without ssr like this: 我目前使用Next.js 动态组件加载没有像这样的ssr

const Select = dynamic(
  () => import('react-select').then((mod) => mod.default),
  {
    ssr: false,
    loading: () => null,
  },
);

Use select component as usual 像往常一样使用选择组件

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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM