使用React Bootstrap模式取消捕获的不变量违规
Uncaught Invariant Violation using React Bootstrap modal
我最近开始玩react,我遇到了一个问题。我不知道为什么它会给我这个问题。我在谷歌和S/O上搜索过,但我找不到我的代码导致错误的原因。
我已经在项目中安装了react-bootstrap。我可以确认这是工作,因为我能够加载所有组件没有任何问题。
然而,在这段代码中,我看到了一个"未捕获的不变量违规:addComponentAsRefTo…"'错误,当我添加一个<Modal/>
包装围绕我的表单(没有包装我的表单工作良好)。
下面是我的一些代码(都包含在同一个组件中):
handleClick() {
var foo = this.refs.foo.value;
...
render() {
var Modal = require('react-bootstrap').Modal;
return (
<Modal show={this.state.showModal} onHide={this.close}>
<div>
<input ref='foo' />
<button onClick={this.handleClick}>Submit</button>
</div>
</Modal>
)
}
...
谁能帮助我理解为什么我得到'ref'错误,当我包装我的表单输入在一个模型组件?
查看react bootstrap源代码,他们希望您使用其子组件包装内容https://react-bootstrap.github.io/components.html#modals-live试试这个:
<Modal show={this.state.showModal} onHide={this.close}>
<Modal.Body>
<div>
<input ref='foo' />
<button onClick={this.handleClick}>Submit</button>
</div>
</Modal.Body>
</Modal>
相关文章:
- 不确定react.js的异步执行时间
- Uncatch TypeError:DB.find 不是 React with Meteor 1.3 中的函数
- React.addons.classSet不是React js函数
- React:未捕获的不变量冲突:ReactDOM.render():无效的组件元素
- Dispatch()调用一个函数,但是.then()不调用;我不在React Redux上工作
- 找不到 react 组件 LoginComponent - ng-React
- 异步处理不影响 React+Flux 中视图的数据
- 渲染时,未定义不是React本机中的对象
- 有没有什么方法可以在这里用node而不是react.js来拉一个json文件
- 模态上的React-不变量冲突
- e.target 是可访问的,但 e.target.value 不在 React 组件中
- 客户端React-Router演示:不变量冲突
- 自定义React Native UI组件:不变量冲突
- 外部react组件看不到react . component
- 不变量冲突:对象作为React的子对象是无效的
- React不变量冲突:对象作为React的子对象是无效的
- 使用React Bootstrap模式取消捕获的不变量违规
- 调用React类的构造函数时的不变量冲突
- 使用Mocha进行React测试时的不变量冲突
- 错误:使用react-router时,不变量违规:addComponentAsRefTo