@@ -24,7 +24,25 @@ import Only from '@uiw/react-only-when'
2424< / Only>
2525```
2626
27- ## \< If>
27+ ``` jsx
28+ import { If } from ' @uiw/react-only-when/if'
29+
30+ < If condition= {props .error }>
31+ < h1> {props .error }< / h1>
32+ < / If>
33+ ```
34+
35+ ``` jsx
36+ import { Switch , Case , Default } from ' @uiw/react-only-when/switch'
37+
38+ < Switch>
39+ < Case condition= {age < 6 }> preschool< / Case>
40+ < Case condition= {age >= 6 }> primary school< / Case>
41+ < Default> you graduated< / Default>
42+ < / Switch>
43+ ```
44+
45+ ## \< If />
2846
2947React component that renders the children if the ` condition ` prop is ` true ` .
3048
@@ -56,7 +74,7 @@ Or you could just use plain JavaScript:
5674< / div>
5775```
5876
59- ## Example
77+ Only Example
6078
6179``` jsx mdx:preview&background=#fff&codePen=true
6280import React , { useState } from ' react' ;
@@ -75,6 +93,38 @@ export default function App() {
7593}
7694```
7795
96+ ## \< Switch />
97+
98+ ``` jsx
99+ import { Switch , Case , Default } from ' @uiw/react-only-when/switch'
100+
101+ < Switch>
102+ < Case condition= {age < 6 }> preschool< / Case>
103+ < Case condition= {age >= 6 }> primary school< / Case>
104+ < Default> you graduated< / Default>
105+ < / Switch>
106+ ```
107+
108+ ``` jsx mdx:preview&background=#fff&codePen=true
109+ import React , { useState , Fragment } from ' react' ;
110+ import { Switch , Case , Default } from ' @uiw/react-only-when/switch'
111+
112+ export default function App () {
113+ const [age , setAge ] = useState (19 )
114+ return (
115+ < Fragment>
116+ < input type= " range" onChange= {(evn ) => setAge (Number (evn .target .value ))} / > {age}
117+ < Switch>
118+ < Case condition= {age < 6 }> Preschool< / Case>
119+ < Case condition= {age >= 6 && age < 18 }> Primary school< / Case>
120+ < Case condition= {age >= 18 }> Went to college< / Case>
121+ < Default> you graduated< / Default>
122+ < / Switch>
123+ < / Fragment>
124+ );
125+ }
126+ ```
127+
78128## props
79129
80130| prop name | type | default | isRequired | description |
0 commit comments