Sha*_*vis 4 javascript reactjs
我有一个用数据 uri 生成的 IMG DOM 元素。如何将它附加到 React.js“虚拟 DOM”?
当我尝试以下操作时:
myImgComponent = React.createClass({
getInitialState: function() {
slowGenerateImage((function(_this) {
return function(img) { /* img is an HTMLImageElement */
return _this.setState({
image: img
});
};
})(this));
return {image: null};
},
render: function() {
return div(
{},
this.state.image /* image is a raw HTMLImageElement */
);
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Invariant Violation: traverseAllChildren(...): Encountered an invalid child; DOM elements are not valid children of React components.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5970 次 |
| 最近记录: |