You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NextJS客户端渲染页面中react-select下拉框未填充求助

NextJS 13中react-select下拉框为空的解决办法

下面是针对你遇到的问题的具体修复步骤:

  • 修正React导入方式
    你的代码中import { React } from "react";是错误写法,正确的导入应该是:

    import React from "react";
    

    或者在NextJS 13+中可以直接省略React导入(JSX会自动转换),但保留正确导入能避免潜在问题。

  • 确保"use client"标识位置正确
    "use client";必须放在文件的最顶部,前面不能有任何空格、注释或其他代码。调整后文件开头应该是:

    "use client";
    import React from "react";
    import Select from "react-select";
    
  • 检查并安装适配版本的react-select
    确保安装的react-select版本与NextJS 13兼容,建议重新安装最新稳定版:

    npm uninstall react-select
    npm install react-select
    
  • 手动导入react-select样式
    部分场景下样式可能未自动加载,导致下拉框内容不可见,手动导入样式文件:

    import "react-select/dist/react-select.css";
    

修改后的完整代码

"use client";

import React from "react";
import Select from "react-select";
import "react-select/dist/react-select.css";

const Page = () => {
  return (
    <>
      <Select
        options={[
          { value: 'one', label: 'One' },
          { value: 'two', label: 'Two' },
        ]}
      />
    </>
  );
};

export default Page;

内容的提问来源于stack exchange,提问作者user4032429

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 01:22:06