0
React Fiber에 구성 요소를 썼습니다. 이 구성 요소는 1 개의 cond props를 수신하며 이는 사실이며 자식을 렌더링합니다.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'를 먼저 평가하지 않고 ''의 자식을 만들 수는 없으며 섬유로 변경되지 않았습니다. –
xs0
죄송합니다. 틀렸어요. 나는 React 15에서 코드를 시도했는데 같은 오류가 발생했다. ... 샘플 코드 https://jsfiddle.net/kmdsbng/9gj83n6x/1/ – kmdsbng