reactjs - 给出错误元素类型无效的所有范围滑块库。我还能尝试什么?
问题描述
我想在我的项目中创建一个滑块,我正在使用 react-rangeslider 库。我写了一篇很简单的文章
const Slider = require('react-rangeslider');
var Para = React.createClass({
handleChange: function(value) {
this.setState({
value: value,
});
},
render: function () {
return (
<Slider
value={this.state.value}
orientation="vertical"
onChange={this.handleChange} />
);
}
});
这导致错误
app.js:6873 Uncaught Invariant Violation: Element 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. Check the render method of `Para`.
版本"react-rangeslider": "^2.2.0"
我尝试过的其他库是 mdbReact、ReactBootstrapSlider。
我确实看到了类似错误的帖子,但所有这些帖子都以不同的方式导入。
解决方案
当您错误地导入组件时会发生此错误。
如果您使用默认导出:
// yourfile.js
const Component;
export default Component;
// anotherFile.js
import yourComponent form './yourfile';
如果您使用命名导出:
// yourfile.js
export const Component;
// anotherFile.js
import { Component } form './yourfile';
推荐阅读
- python - 有人可以向我解释一下这一行:'\n'.join([f"{n} x {i} = {n*i}" for i in range(1,11)?
- python - 使用 xpaths 抓取 Amazon 表的特定部分时出错
- html - 小于 x 的数字的正则表达式?
- mysql - Keycloak 无法连接到我的 MySQL 数据库
- python-3.x - 我不知道为什么你需要在括号内添加加号和撇号,当它在 python 中的字符串函数内时
- json - 如何替换特定 JSON 字段中的字符?
- powerbi - 折线图 Power BI 中的移动平均线
- c# - 允许此预编译站点可更新 Visual Studio 2019
- windows - 如何通过 PowerShell 或 java 在 Windows 资源管理器中获取“状态”列值
- c++ - 在 2D 向量上执行单行算术以找到简化的行形式 C++