-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
executable file
·36 lines (29 loc) · 909 Bytes
/
example.js
File metadata and controls
executable file
·36 lines (29 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// src/example.js
import React, { useState } from 'react';
const MyComponent = () => {
const [count, setCount] = useState(0);
const [isVisible, setIsVisible] = useState(true);
const handleIncrement = () => {
setCount(prevCount => prevCount + 1);
};
const toggleVisibility = () => {
setIsVisible(prev => !prev);
};
return (
<div className="my-component">
<h2>My Example Component</h2>
{isVisible && (
<div className="counter-section">
<p>Count: {count}</p>
<button onClick={handleIncrement}>
Increment
</button>
</div>
)}
<button onClick={toggleVisibility}>
{isVisible ? 'Hide' : 'Show'} Counter
</button>
</div>
);
};
export default MyComponent;