我在阵营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这应该是一个被接受的答案,我想。首先防止组件被渲染。 –