Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
47ca2c4d
Commit
47ca2c4d
authored
6 years ago
by
Dan Abramov
Browse files
Options
Download
Email Patches
Plain Diff
MVP
parent
baa9051b
github/fork/gaearon/hot-reload-again
1 merge request
!5958
[WIP] Hot reloading (only for Hooks)
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
packages/babel-plugin-hot-reload/index.js
+3
-11
packages/babel-plugin-hot-reload/index.js
packages/react-scripts/template/src/App.js
+3
-1
packages/react-scripts/template/src/App.js
packages/react-scripts/template/src/CounterClass.js
+17
-0
packages/react-scripts/template/src/CounterClass.js
packages/react-scripts/template/src/Hello.js
+14
-0
packages/react-scripts/template/src/Hello.js
packages/react-scripts/template/src/index.js
+4
-0
packages/react-scripts/template/src/index.js
with
41 additions
and
12 deletions
+41
-12
packages/babel-plugin-hot-reload/index.js
+
3
-
11
View file @
47ca2c4d
...
...
@@ -112,21 +112,13 @@ module.exports = function({ types: t }) {
decorateFunctionId
(
t
,
name
,
generatedName
),
template
(
`
if (!module.hot.data) {
module.hot.accept();
} else {
module.hot.data.acceptNext = () => module.hot.accept();
}
module.hot.accept();
`
)(),
template
(
`
module.hot.dispose(data => {
window.__enqueueForceUpdate(() => {
if (typeof data.acceptNext === 'function') {
data.acceptNext();
}
}, NAME);
module.hot.dispose(() => {
window.__enqueueForceUpdate(NAME);
});
`
)({
NAME
:
t
.
Identifier
(
name
)
}),
...
...
This diff is collapsed.
Click to expand it.
packages/react-scripts/template/src/App.js
+
3
-
1
View file @
47ca2c4d
import
React
,
{
Component
}
from
'
react
'
;
import
Hello
from
'
./Hello
'
;
import
logo
from
'
./logo.svg
'
;
import
'
./App.css
'
;
class
App
extends
Component
{
render
()
{
return
(
<
div
className
=
"
App
"
>
<
div
className
=
"
App
"
onClick
=
{()
=>
this
.
forceUpdate
()}
>
<
header
className
=
"
App-header
"
>
<
img
src
=
{
logo
}
className
=
"
App-logo
"
alt
=
"
logo
"
/>
<
Hello
/>
<
p
>
Edit
<
code
>
src
/
App
.
js
<
/code> and save to reload
.
<
/p
>
...
...
This diff is collapsed.
Click to expand it.
packages/react-scripts/template/src/CounterClass.js
0 → 100644
+
17
-
0
View file @
47ca2c4d
import
{
Component
}
from
'
react
'
;
export
default
class
Counter
extends
Component
{
state
=
{
value
:
0
};
componentDidMount
()
{
this
.
interval
=
setInterval
(
()
=>
this
.
setState
(
s
=>
({
value
:
s
.
value
+
1
})),
1000
);
}
componentWillUnmount
()
{
clearInterval
(
this
.
interval
);
}
render
()
{
return
this
.
state
.
value
;
}
}
This diff is collapsed.
Click to expand it.
packages/react-scripts/template/src/Hello.js
0 → 100644
+
14
-
0
View file @
47ca2c4d
import
React
,
{
useState
}
from
'
react
'
;
import
CounterClass
from
'
./CounterClass
'
;
export
default
function
Hello
()
{
const
[
value
]
=
useState
(
Math
.
random
());
return
(
<
h1
>
{
value
.
toString
().
slice
(
0
,
5
)}
<
br
/>
b
<
CounterClass
/>
<
/h1
>
);
}
This diff is collapsed.
Click to expand it.
packages/react-scripts/template/src/index.js
+
4
-
0
View file @
47ca2c4d
...
...
@@ -4,6 +4,10 @@ import './index.css';
import
App
from
'
./App
'
;
import
*
as
serviceWorker
from
'
./serviceWorker
'
;
window
.
__enqueueForceUpdate
=
function
(
type
)
{
console
.
log
(
type
);
};
ReactDOM
.
render
(
<
App
/>
,
document
.
getElementById
(
'
root
'
));
// If you want your app to work offline and load faster, you can change
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets