我在陣營0.14是曾在陣營0.13無國籍功能組件,但現在返回以下錯誤:返回null從一個無狀態的組件/「功能組件」
No
render
method found on the returned component instance: you may have forgotten to definerender
, returned null/false from a stateless component, or tried to render an element whose type is a function that isn't a React component.
這是我的組件:
function ToggleDisplay(props) {
//should render a <noscript> per React's implementation
if(props.if === false) {
// return <noscript></noscript>; //do I have to do this manually now?
return null;
}
let style = {};
if(shouldHide(props)) {
style.display = 'none';
}
return (
<span style={style} {...props} />
);
}
我必須現在手動返回<noscript>
嗎?有沒有無狀態組件返回null的另一種方法?
爲什麼你不在父母級別渲染? –
還有https://www.npmjs.com/package/react-component-empty –
@DominicTobias這應該是一個被接受的答案,我想。首先防止組件被渲染。 –