File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -1052,4 +1052,28 @@ const FunctionalComponent() {
10521052 export const ChildComponent = ( { func, ...props } ) => {
10531053 func ( 'This is data' )
10541054 return < > </ >
1055- } ;
1055+ } ;
1056+
1057+
1058+
1059+ // STATE
1060+ import { useState } from 'react' ;
1061+ const FunctionalComponent = ( ) => {
1062+ const [ count , setCount ] = useState ( 0 ) ;
1063+ return (
1064+ < div >
1065+ < p > count: { count } </ p >
1066+ < button onClick = { ( ) => setCount ( count + 1 ) } > +</ button >
1067+ </ div >
1068+ ) ;
1069+ } ;
1070+ // OR conditional rendering based on state
1071+ const FunctionalComponent = ( ) => {
1072+ const [ show , setShow ] = useState ( false ) ;
1073+ return (
1074+ < div >
1075+ < button onClick = { ( ) => setShow ( ! show ) } > { show ? 'Hide' : 'Show' } </ button >
1076+ { show && < p > { show ? `Ì'm visible` : `Ì'm not visible` } </ p > }
1077+ </ div >
1078+ ) ;
1079+ } ;
You can’t perform that action at this time.
0 commit comments