[TypeScript] Refresh not working with arrow functions
See original GitHub issueHey There,
I’m running into issues getting hot reloading working in my webpack-typescript app:
I’m only getting this error when I use arrow functions to declare my React components:
// hot-reload doesn't work
const App = () => {
return ....
}
export default App
// hot-reload works
function App () {
return ...
}
export default App;
This approach works when I use the sample project though.
https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/217
plugins: [
new ReactRefreshPlugin(),
new ForkTsCheckerWebpackPlugin(),
new HtmlWebpackPlugin({
filename: './index.html',
template: './public/index.html',
}),
]
Dependencies:
"fork-ts-checker-webpack-plugin": "^6.0.6",
"html-webpack-inline-source-plugin": "^0.0.10",
"html-webpack-plugin": "^4.4.1",
"react-refresh": "^0.9.0",
"react-refresh-typescript": "^1.1.0",
"style-loader": "^0.23.1",
"ts-loader": "^8.0.4",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0",
Any ideas on what is causing this issue?
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Anonymous arrow functions cause Fast Refresh to not ...
I have this code in my pages/index.js file: import React from 'react'; import dynamic from ...
Read more >Anonymous arrow functions cause Fast Refresh to ... - GitHub
When running the example with npm run dev The following warning is displayed in the console: Anonymous arrow functions cause Fast Refresh to ......
Read more >Basic Features: Fast Refresh - Next.js
Next.js' Fast Refresh is a new hot reloading experience that gives you ... arrow functions like export default () => <div />; cause...
Read more >Arrow Function Snippets - Visual Studio Marketplace
The arrow function allows to accomplish the same result with fewer lines of code and approximately half the typing. Curly brackets aren't required...
Read more >Use ES6 Arrow Functions to Resolve "TypeError - Pluralsight
To do this, you can use ES6 arrow functions. Apart from making your code more succinct and readable, arrow functions serve another purpose....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tried to reproduce this and found it’s likely not a bug in
react-refresh-typescript
.If
used as entry component
means the following code:Yes, in this case, it won’t refresh but reload the whole tree. Because every time this file getting HMRed, this whole file will be re-executed. And if you re-call
ReactDOM.render
(the last line) on your root component, it will be unmounted and remounted, because the previousApp
has a different identity than the currentApp
, and the reconciliation algorithms will not diff the vDOM tree for a different component tree.If it is your case, please move
App
to another file, that will fix the problem. If not, please point out and give a reproduce. ThanksHi, I have exactly the same problem, but I have come to the conclusion that the arrow functions do not have to do with it. As far as I understand, it’s all about the use of hooks.
I also noticed that in React Developer Tools, the arrow function components are named
<Anonymous>
. Most likely the problem is in react-refresh-typescript, for some reason the component loses displayName.