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

Shadow-cljs中如何正确引入react-select的Creatable组件?

正确引入react-select Creatable组件的Shadow-cljs方案
  • 首先确保已安装最新版react-select:

    npm install react-select
    
  • 在CLJS命名空间中按以下方式引入Creatable组件及相关钩子:

    (ns your.app.namespace
      (:require
       [reagent.core :as ra]
       ;; 标准Select组件
       ["react-select" :default Select]
       ;; Creatable组件及useCreatable钩子
       ["react-select/creatable" :default Creatable :refer (useCreatable)]))
    
  • 将Creatable适配为Reagent组件:

    (def dropdown-creatable (ra/adapt-react-class Creatable))
    
  • 直接使用示例:

    (defn sample-creatable-dropdown []
      [dropdown-creatable
       {:options [{:value "cat" :label "Cat"}
                  {:value "dog" :label "Dog"}]
        :on-change (fn [selected] (js/console.log "选择/创建了:" selected))}])
    

如果之前尝试子路径导入时出现"找不到npm包react-select/creatable"的错误,执行以下步骤修复:

  1. 运行npx shadow-cljs clean清除Shadow-cljs缓存
  2. 重启Shadow-cljs编译服务
  3. 确认你的react-select版本在v4及以上(旧版本的Creatable导出结构不同)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 15:32:07