-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.tsx
More file actions
42 lines (35 loc) · 959 Bytes
/
Copy pathtest.tsx
File metadata and controls
42 lines (35 loc) · 959 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
37
38
39
40
41
42
import React, { useState, useEffect } from 'react';
interface Props {
title: string;
count?: number;
}
const TestComponent: React.FC<Props> = ({ title, count = 0 }) => {
const [value, setValue] = useState<number>(count);
const [isVisible, setIsVisible] = useState<boolean>(true);
useEffect(() => {
console.log("Component mounted with title:", title);
}, [title]);
const handleIncrement = (): void => {
setValue(prev => prev + 1);
};
const handleToggle = (): void => {
setIsVisible(!isVisible);
};
return (
<div className="container">
<h1>{title}</h1>
{isVisible && (
<div>
<p>Current value: {value}</p>
<button onClick={handleIncrement} type="button">
Increment
</button>
<button onClick={handleToggle} type="button">
Toggle Visibility
</button>
</div>
)}
</div>
);
};
export default TestComponent;