title | description | authors | tags | categories | date | draft | archive | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Conditional Render in React |
Some description ... |
|
|
|
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.