Skip to content

Commit 4f1e580

Browse files
committed
refactor: simple-counter.js
1 parent 7fe7863 commit 4f1e580

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

solutions/simple-counter.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
import React, { useState } from 'react';
2-
import ReactDOM from 'react-dom';
1+
import React, { useState } from "react"
2+
import { createRoot } from "react-dom/client"
33

44
const Counter = () => {
5-
const [count, setCount] = useState(0);
5+
const [count, setCount] = useState(0)
66

7-
increment = () => {
8-
setCount(prevCount => prevCount + 1);
9-
};
7+
const increment = () => {
8+
setCount(prevCount => prevCount + 1)
9+
}
1010

11-
return (
12-
<div id="mainArea">
13-
<p>
14-
Button Count:
15-
<span>{count}</span>
16-
</p>
17-
<button
18-
onClick={increment}
19-
id="mainButton"
20-
>
21-
Increase
22-
</button>
23-
</div>
24-
);
25-
};
11+
return (
12+
<div id="mainArea">
13+
<p>
14+
{`Button Count: `}
15+
<span>{count}</span>
16+
</p>
17+
<button onClick={increment} id="mainButton">
18+
Increase
19+
</button>
20+
</div>
21+
)
22+
}
2623

27-
ReactDOM.render(
28-
<Counter />,
29-
document.getElementById('root')
30-
);
24+
const root = createRoot(document.getElementById("root"))
25+
root.render(<Counter />)

0 commit comments

Comments
 (0)