switch in react code example
Example 1: switch in react
renderSwitch(param) {
switch(param) {
case 'foo':
return 'bar';
default:
return 'foo';
}
}
render() {
return (
<div>
<div>
</div>
{this.renderSwitch(param)}
<div>
</div>
</div>
);
}
Example 2: react router switch
ReactDOM.render((
<Switch>
<Route exact path="/" component={Home} />
<Route path="/login" component={Login} />
<Route path="/explore" component={Explore} />
</Switch>),
document.getElementById('root')
);
Example 3: Switch Button in react
> npm i bootstrap-switch-button-react --save
import BootstrapSwitchButton from 'bootstrap-switch-button-react'
<BootstrapSwitchButton
onlabel='Hide'
onstyle='danger'
offlabel='Show'
offstyle='success'
style="border"
width={80}
onChange={() => {
handleReload()
}} />
<label> Show Hide Switch Button </label>
Example 4: typescript react switch case component
render() {
return (
<>
{
{
foo: <Foo />,
bar: <Bar />
}[param]
}
</>
)
}