Declarative way to render components conditionally
npm install react-switchcase-condition
Declarative way to render components conditionally
```
npm install --save react-switchcase-conditionOR
yarn add react-switchcase-condition
`js
import {
Switch,
Case,
Default,
} from 'react-switchcase-condition';
const Test1 = ({ text }) =>
const Demo = () => (
component={Test1}
componentProps={{ text: 'This will not be rendered', }}
/>
component={Test2}
componentProps={{ text: 'This will be render', }}
/>
componentProps={{ text: 'This is the default render' }}
/>
);
`
Wrapper component to declare the Switch block. Its children must contain at least one Case and exact one Default component. The first Case whose cond is true will be rendered. If there is no cond-true Case, Default will be rendered.
Declare a render case
| Prop Name | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| cond | bool | true | |Condition to determine render. Render if true and is the first Case in children list |
| component | React component | true | | Component to render if cond is true |component
| componentProps | object | false | {} | Props passed to to render if cond is true |
Declare the default render case
| Prop Name | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| component | React component | true | | Component to render if there is no cond-true Case |component` to render |
| componentProps | object | false | {} | Props passed to