我在React光纤上写了component。这个组件收到1个cond props,这是真的,渲染子组件。
"use strict";
import * as React from "react";
import * as ReactDOM from "react-dom";
interface IfProps {
cond: boolean;
}
export class If extends React.Component<IfProps, {}> {
render() {
const {cond, children} = this.props;
if (cond) {
return children;
} else {
return null;
}
}
}
class TopComponent extends React.Component {
render() {
let str: any = null;
return (
<div>
<If cond={str != null}>
This part not showed.
{str.length}
</If>
</div>
);
}
}
ReactDOM.render(<TopComponent />, document.getElementById("app"));在React纤程之前,这段代码可以工作。但是现在,React纤程导致了错误。
Uncaught TypeError: Cannot read property 'length' of null我猜React纤程会在组件渲染之前渲染子组件。但是这个行为破坏了组件。
我可以停止组件的预渲染子项吗?
https://stackoverflow.com/questions/47673003
复制相似问题