Skip to content

Latest commit

 

History

History
25 lines (25 loc) · 724 Bytes

conditional-render-in-react.md

File metadata and controls

25 lines (25 loc) · 724 Bytes
title description authors tags categories date draft archive
Conditional Render in React
Some description ...
lek-tin
frontend
javascript
react
reconciliation-key
javascript
2018-08-28 23:31:12 +0800
false
false

In react, sometimes we need to render a component based on some flag, for example, we need to display a different set of information to the admin users than the normal users. We have a prop called isAdmin

render () {
  const { isAdmin } = this.props
  return (
    <div>
      { isAdmin
        ? <CustomeComponent {...propSetA} / >
        : <CustomeComponent {...propSetB} / >
      }
    </div>
  )
}

Looks good right, but there is one problem.