Skip to content

Commit 0de030f

Browse files
committed
Convert screenshotButton to a functional component, and add types to components
1 parent 4a007a1 commit 0de030f

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { Component, h } from 'preact';
1+
import {h, render} from 'preact';
2+
import {useState, useCallback} from 'preact/hooks';
3+
import type {VNode} from 'preact';
24

3-
export class ScreenshotButton extends Component {
4-
state = { clicked: false };
5-
handleClick = () => {
6-
this.setState({ clicked: !this.state.clicked });
7-
};
8-
render() {
9-
return (
10-
<label htmlFor="screenshot" className="form__label">
11-
<span className="form__label__text">Screenshot</span>
12-
<button class="btn btn--default" type="screenshot" onClick={this.handleClick}>
13-
{this.state.clicked ? 'Remove' : 'Add'}
14-
</button>
15-
</label>
16-
);
17-
}
5+
export function ScreenshotButton(): VNode {
6+
const [clicked, setClicked] = useState(false);
7+
const handleClick = useCallback(() => {
8+
setClicked(prev => !prev);
9+
}, []);
10+
11+
return (
12+
<label htmlFor="screenshot" className="form__label">
13+
<span className="form__label__text">Screenshot</span>
14+
<button class="btn btn--default" type="screenshot" onClick={handleClick}>
15+
{clicked ? 'Remove' : 'Add'}
16+
</button>
17+
</label>
18+
);
1819
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { h } from 'preact';
2-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
3-
export function ScreenshotWidget() {
1+
import {h, render} from 'preact';
2+
import type {VNode} from 'preact';
3+
4+
export function ScreenshotWidget(): VNode {
45
return <div style="height:100px; width: 100px; background:red;" />;
56
}

0 commit comments

Comments
 (0)