monsterooo / blog

and make promises by the hours
MIT License
14 stars 1 forks source link

recompose renderNothing #21

Open monsterooo opened 6 years ago

monsterooo commented 6 years ago

renderNothing 介绍

renderNothing和它的名字一样,它是一个返回null的高阶组件

renderNothing Flow Type

renderNothing: HigherOrderComponent

renderNothing 例子

const { compose, branch, renderNothing } = Recompose;

const Bar = () => (<p>Bar</p>);

const Foo = compose(
  branch(
    props => props.isShow,
    () => Bar,
    renderNothing,
  ),
)(({ title }) => (
  <div>{ title }</div>
))

class App extends React.Component {
  render() {
    return (
      <div>
        什么组件也不展示
        <Foo isShow={false} />
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('app'))

在线DEMO

codepen在线预览