-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Experimental React Refresh Example (#12081)
* Add Experimental React Refresh Example * add basic readme
- Loading branch information
Showing
8 changed files
with
162 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# z-experimental-refresh | ||
|
||
This is an **experimental** demo of React Fast Refresh. | ||
Please do not use these features in your application or project (yet). | ||
|
||
## Usage | ||
|
||
Run the following command to get started: | ||
|
||
```bash | ||
yarn dev | ||
# or | ||
npm run dev | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useCallback, useState } from 'react' | ||
import styles from './ClickCount.module.css' | ||
|
||
export default function ClickCount() { | ||
const [count, setCount] = useState(0) | ||
const increment = useCallback(() => { | ||
setCount(v => v + 1) | ||
}, [setCount]) | ||
|
||
return ( | ||
<button className={styles.btn} type="button" onClick={increment}> | ||
Clicks: {count} | ||
</button> | ||
) | ||
} |
32 changes: 32 additions & 0 deletions
32
examples/z-experimental-refresh/components/ClickCount.module.css
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
button.btn { | ||
margin: 0; | ||
border: 1px solid #d1d1d1; | ||
border-radius: 5px; | ||
padding: 0.5em; | ||
vertical-align: middle; | ||
white-space: normal; | ||
background: none; | ||
line-height: 1; | ||
font-size: 1rem; | ||
font-family: inherit; | ||
transition: all 0.2s ease; | ||
} | ||
|
||
button.btn { | ||
padding: 0.65em 1em; | ||
background: #0076ff; | ||
color: #fff; | ||
border: none; | ||
cursor: pointer; | ||
transition: all 0.2s ease; | ||
} | ||
button.btn:focus { | ||
outline: 0; | ||
border-color: #0076ff; | ||
} | ||
button.btn:hover { | ||
background: rgba(0, 118, 255, 0.8); | ||
} | ||
button.btn:focus { | ||
box-shadow: 0 0 0 2px rgba(0, 118, 255, 0.5); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
body { | ||
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica', | ||
'Arial', sans-serif; | ||
padding: 20px 20px 60px; | ||
max-width: 680px; | ||
margin: 0 auto; | ||
font-size: 16px; | ||
line-height: 1.65; | ||
word-break: break-word; | ||
font-kerning: auto; | ||
font-variant: normal; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-rendering: optimizeLegibility; | ||
hyphens: auto; | ||
} | ||
|
||
h2, | ||
h3, | ||
h4 { | ||
margin-top: 1.5em; | ||
} | ||
|
||
code, | ||
pre { | ||
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, | ||
Bitstream Vera Sans Mono, Courier New, monospace, serif; | ||
font-size: 0.92em; | ||
color: #d400ff; | ||
} | ||
|
||
code:before, | ||
code:after { | ||
content: '`'; | ||
} | ||
|
||
hr { | ||
border: none; | ||
border-bottom: 1px solid #efefef; | ||
margin: 6em auto; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
reactRefresh: true, | ||
}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "z-experimental-refresh", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"next": "canary", | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0" | ||
}, | ||
"license": "MIT" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../global.css' | ||
|
||
export default function MyApp({ Component, pageProps }) { | ||
return <Component {...pageProps} /> | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useCallback, useEffect, useState } from 'react' | ||
import ClickCount from '../components/ClickCount' | ||
|
||
function Home() { | ||
const [count, setCount] = useState(0) | ||
const increment = useCallback(() => { | ||
setCount(v => v + 1) | ||
}, [setCount]) | ||
|
||
useEffect(() => { | ||
const r = setInterval(() => { | ||
increment() | ||
}, 250) | ||
return () => { | ||
clearInterval(r) | ||
} | ||
}, [increment]) | ||
|
||
return ( | ||
<main> | ||
<h1>Home</h1> | ||
<div> | ||
<p>Auto Incrementing Value</p> | ||
<p>Current value: {count}</p> | ||
</div> | ||
<hr /> | ||
<div> | ||
<p>Component with State</p> | ||
<ClickCount /> | ||
</div> | ||
</main> | ||
) | ||
} | ||
|
||
export default Home |