IssueRaiser

Feedback wanted: New Hot Reloading

I’m working on hot reloading again. Got a very raw alpha version working. It preserves state but only for function components. Works with Hooks. You can try the alpha version (**not production ready, super experimental**): ### Trying in a New Project (NOT FOR PRODUCTION) ``` npx create-react-app demo --scripts-version wonky-scripts ``` ### Trying in an Existing Project (NOT FOR PRODUCTION) 1. Replace `react-scripts` dependency with `wonky-scripts@0.0.5` 2. Keep `scripts` the same 3. Delete `node_modules/.cache` 4. Run Yarn/npm 5. Start the project and try editing your React components ### What It Looks Like It’s expected that it will work something like on this gif: https://twitter.com/dan_abramov/status/1139876172903395329 ### Constraints (Library Authors, Read This!) If your Hook or Component doesn't work with hot reload, keep in mind that: * `useMemo` and `useCallback` caches are dropped on every edit (otherwise there wouldn't be a way to edit them 😅). If this breaks your code, consider `useRef` which gives you a semantics guarantee about not getting re-created. Like [here](https://github.com/alexreardon/use-memo-one). Usually there's a way to restructure the code to be more resilient. * Same goes for `useEffect`. During hot reload, dependency array will be ignored, and even effects with `[]` dependencies will re-run. If this breaks your component or Hook, there's likely a way to restructure it to fix this. As a bonus, this will make it easier for you to later

Posted by gaearon on Jun 15, 2019, 1:07 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (SaaS)

Feedback wanted: New Hot Reloading

gaearonJun 15, 2019, 1:07 PM

I’m working on hot reloading again. Got a very raw alpha version working. It preserves state but only for function components. Works with Hooks. You can try the alpha version (**not production ready, super experimental**): ### Trying in a New Project (NOT FOR PRODUCTION) ``` npx create-react-app demo --scripts-version wonky-scripts ``` ### Trying in an Existing Project (NOT FOR PRODUCTION) 1. Replace `react-scripts` dependency with `wonky-scripts@0.0.5` 2. Keep `scripts` the same 3. Delete `node_modules/.cache` 4. Run Yarn/npm 5. Start the project and try editing your React components ### What It Looks Like It’s expected that it will work something like on this gif: https://twitter.com/dan_abramov/status/1139876172903395329 ### Constraints (Library Authors, Read This!) If your Hook or Component doesn't work with hot reload, keep in mind that: * `useMemo` and `useCallback` caches are dropped on every edit (otherwise there wouldn't be a way to edit them 😅). If this breaks your code, consider `useRef` which gives you a semantics guarantee about not getting re-created. Like [here](https://github.com/alexreardon/use-memo-one). Usually there's a way to restructure the code to be more resilient. * Same goes for `useEffect`. During hot reload, dependency array will be ignored, and even effects with `[]` dependencies will re-run. If this breaks your component or Hook, there's likely a way to restructure it to fix this. As a bonus, this will make it easier for you to later

Comments (0)

No comments yet. Start the discussion.

Comment on this issue