-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: page doesn't reload when can't hot update
- Loading branch information
Showing
2 changed files
with
34 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
import React from 'react'; | ||
import React, { memo } from 'react'; | ||
import { hot } from 'react-hot-loader/root'; | ||
|
||
import './App.scss'; | ||
|
||
const App = () => { | ||
const [count, setCount] = React.useState(0); | ||
interface CounterProps { | ||
initialCount?: number; | ||
} | ||
|
||
const Counter = memo(function Counter({ initialCount = 0 }: CounterProps) { | ||
const [count, setCount] = React.useState(initialCount); | ||
|
||
const add = () => { | ||
setCount(count + 1); | ||
}; | ||
|
||
return ( | ||
<div className="counter"> | ||
<input type="text" value={count} readOnly /> | ||
<button type="button" onClick={add}> | ||
+ | ||
</button> | ||
</div> | ||
); | ||
}); | ||
|
||
function App() { | ||
return ( | ||
<div className="app"> | ||
<h2 className="title">react typescript boilerplate</h2> | ||
<div className="counter"> | ||
<input type="text" value={count} readOnly /> | ||
<button type="button" onClick={add}> | ||
+ | ||
</button> | ||
</div> | ||
<Counter /> | ||
</div> | ||
); | ||
}; | ||
} | ||
|
||
export default hot(App); |