【发布时间】:2019-03-13 20:28:37
【问题描述】:
我正在尝试使用这个 React 库 (https://www.npmjs.com/package/react-toggle-component),但很难让它工作。
我已经通过 npm 安装了所需的依赖项(react、react-circle、react-dom 和 styled-components)。
安装这些依赖项并尝试安装 react-toggle-component 后,我收到错误“找不到模块“react”的声明文件。尝试npm install @types/react(样式组件的相同错误)。所以我按照这个命令成功安装了react-toggle-component。
现在,当我尝试在我的 react 组件中使用该组件时,我正在使用它,就像在建议的用法中一样:
import React from "react"
import Toggle from "react-toggle-component"
function Application() {
return <Toggle name="toggle-1" />;
}
但是当我运行我的应用程序时,我收到以下错误:
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
我不完全明白为什么我必须安装 react 和 styled-components 的类型定义,我想知道这是否会导致我的应用程序找不到 Toggle 组件。
如果你能指出我正确的方向,或者给我任何理解这一点的帮助,我将非常感激!
【问题讨论】: