- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我似乎误解了 React.js 的一些基本部分。
在http://facebook.github.io/react/docs/component-api.html
它说,一个 react 组件有像 setState() 这样的方法。
但是当我这样做的时候:
var MyComp = React.createClass({
getInitialState: function() {
return {dummy: "hello"};
},
render: function() { return React.DOM.h1(null, this.state.dummy + ", world!") }
}
var newComp = MyComp(null);
React.renderComponent(newComp, myDomElement);
MyComp.setState({dummy: "Good Bye"}); // Doesn't work. setState does not exist
newComp.setState({dummy: "Good Bye"}); // Doesn't work either. setState does not exist
找不到 setState() 方法。但是在文档中它说是 Component API,那么我在这里弄错了什么?
最佳答案
根据这个blog post和 this writeup ,调用 MyComp
不再返回实例,它返回一个轻量级描述符。
反模式:
var MyComponent = React.createClass({
customMethod: function() {
return this.props.foo === 'bar';
},
render: function() {
}
});
var component = <MyComponent foo="bar" />;
component.customMethod(); // invalid use!
正确用法:
var MyComponent = React.createClass({
customMethod: function() {
return this.props.foo === 'bar';
},
render: function() {
}
});
var realInstance = React.renderComponent(<MyComponent foo="bar" />, root);
realInstance.customMethod(); // this is valid
关于javascript - react.js ReactComponent 不提供 setState()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25791955/
我正在构建一个小型 React js 应用程序,但收到此错误: Uncaught Error: Invariant Violation: exports.render(): A valid React
我正在学习 React 教程,但我被卡住了。我正在尝试更改控制台中元素的状态。但是当我输入这个时 reactComponent.setState({ isVisible:false }) 我从
我需要一个正则表达式来查找 或 替换为空字符串。它们可以跨多行定义。 这不是 html 或 xhtml,它只是一个包含 的文本字符串和 字段示例: FieldArray 示例:
我需要找到组件的offsetLeft。 componentDidMount(){ var tesNo =ReactDOM.findDOMNode(this.refs.dropDown.
我似乎误解了 React.js 的一些基本部分。 在http://facebook.github.io/react/docs/component-api.html 它说,一个 react 组件有像 s
我正在构建这个简单的 React 应用程序,我遇到了这个错误,我试图调试它但还没有成功。我确信我一定遗漏了一些很明显的重要信息。 *Error: VideoDetail.render(): A val
我正在将 SVG 导入到我的组件中,并使用 ReactComponent 将它们作为组件导入 IE。 import { ReactComponent as D1 } from '../../../as
我在控制台中收到上述错误,即使我正确地返回了要渲染的组件。以下代码中 errorTexts = ["email is invalid"] 的值 if(@state.errorTexts.length>
我使用 CRA 创建了一个新的 React 应用程序。现在,我想创建一个导出所有图标的索引文件。为此,我将所有图标存储在我的 src/icons 中。文件夹并创建一个索引文件,将我的图标导出为 Rea
我使用 CRA 创建了一个新的 React 应用程序。现在,我想创建一个导出所有图标的索引文件。为此,我将所有图标存储在我的 src/icons 中。文件夹并创建一个索引文件,将我的图标导出为 Rea
尝试将 svg 加载为 ReactComponent 时出现以下错误。 Element type is invalid: expected a string (for built-in compone
我正在尝试使用 TypeScript 将 .svg 文件导入为 React 组件。 根据 React 文档,这样做是这样的: 从 './Icon.svg' 导入 { ReactComponent as
使用时: } /> 在typescript LoginLayout中提示错误时: Type '{ history: History; location: Location; match: match
使用时: } /> 在typescript LoginLayout中提示错误时: Type '{ history: History; location: Location; match: match
我是一名优秀的程序员,十分优秀!