Skip to content

Commit b92e15a

Browse files
STATE
1 parent 065ea86 commit b92e15a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

react.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
};

0 commit comments

Comments
 (0)