首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到模块react-select with material ui示例

找不到模块react-select with material ui示例
EN

Stack Overflow用户
提问于 2019-07-03 18:24:44
回答 2查看 760关注 0票数 0

在我自己的例子中,我正在努力实现一个带有material ui的react-select版本。文档中给出的示例非常复杂。https://material-ui.com/components/autocomplete/

当我试图复制代码时,我得到了以下错误

代码语言:javascript
复制
ERROR in [at-loader] ./src/public/components/select.tsx:13:37
    TS2307: Cannot find module 'react-select/lib/components/containers'.

用于以下依赖项。

代码语言:javascript
复制
import { ValueContainerProps } from "react-select/lib/components/containers";
import { ControlProps } from "react-select/lib/components/Control";
import { MenuProps, NoticeProps } from "react-select/lib/components/Menu";
import { MultiValueProps } from "react-select/lib/components/MultiValue";
import { OptionProps } from "react-select/lib/components/Option";
import { PlaceholderProps } from "react-select/lib/components/Placeholder";
import { SingleValueProps } from "react-select/lib/components/SingleValue";
import { ValueType } from "react-select/lib/types";

我已经安装了@types/react-select和react-select。

EN

回答 2

Stack Overflow用户

发布于 2019-07-03 18:39:47

你可以尝试像这样导入(没有实际的路径)-

代码语言:javascript
复制
import { ValueContainerProps } from "react-select";

在react-select中也没有'lib‘文件夹。你确定你给的路是对的吗?

票数 1
EN

Stack Overflow用户

发布于 2019-07-03 18:53:26

您在帖子中提供的链接,即- https://material-ui.com/components/autocomplete/

此链接不包含任何导入

代码语言:javascript
复制
import { ValueContainerProps } from "react-select/lib/components/containers";
import { ControlProps } from "react-select/lib/components/Control";
import { MenuProps, NoticeProps } from "react-select/lib/components/Menu";
import { MultiValueProps } from "react-select/lib/components/MultiValue";
import { OptionProps } from "react-select/lib/components/Option";
import { PlaceholderProps } from "react-select/lib/components/Placeholder";
import { SingleValueProps } from "react-select/lib/components/SingleValue";
import { ValueType } from "react-select/lib/types";

让你的react-select工作的简单步骤,

  1. Install react-select使用,

在组件中yarn add react-select / npm install react-select --save

  • Import默认导出和渲染:

import Select from 'react-select'

  • Usage,

<Select options={options} />

你需要在这里传递options,选项只是你的下拉选项。

代码语言:javascript
复制
const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56867995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档