0
React Fiberにコンポーネントを書きました。 このコンポーネントは1つのcond propsを受け取り、それはtrueで、子をレンダリングします。React Fiberでプリレンダー子をブロックすることはできますか?
"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 Fiberの前に、このコードが機能します。しかし今、React Fiberはエラーを引き起こします。
Uncaught TypeError: Cannot read property 'length' of null
コンポーネントがレンダリングされる前にReact Fiberが子をレンダリングすると思います。 しかし、この動作はコンポーネントを破壊します。
コンポーネントの子要素を事前レンダリングするのを停止できますか?
これは以前には正常に機能しましたか?最初に 'str.length'を評価せずに、' 'の子を構築することはできません。それはFiberで変更されていません。 –
xs0
申し訳ありません、私は間違っていました。私はReact 15でコードを試しましたが、同じエラーが発生しました... サンプルコード https://jsfiddle.net/kmdsbng/9gj83n6x/1/ – kmdsbng