1

I use React with Snowpack and the react-refresh plugin.

After a change, the snowpack dev server recompiles correctly and the browser receives an HMR update signal - but the content is not reloaded, the changes are only visible after manual reloading of the page.

enter image description here

I have tested with Firefox, Chrome and Brave.

According to the documentation you don't have to configure anything else than to include the plugin.

Does anyone have an idea? Would be very grateful!

stoniemahonie
  • 321
  • 1
  • 5
  • 13

1 Answers1

2

Is your state management mobx?

If mobx is used, the component is optimized for memory by the observer, so the mobx state management must be updated to render.

In other words, the observer() has to React.memo applied, and it is rendered again only when a state change occurs.

So if you use useObserver(() => {}) it will work

Ali Asgher Badshah
  • 811
  • 1
  • 11
  • 34
  • Bingo, I actually used mobx! Your explanation sounds conclusive, I guess that was the problem. I have since switched from Snowpack to Create React App, so I can't verify it definitively - thanks anyway, maybe it will help others! – stoniemahonie Jan 10 '21 at 10:09
  • Actually, I modified the code during execution, but there was a problem that did not change the same, so I found and confirmed that it was resolved. – KimKwangHoon Jan 15 '21 at 16:40
  • @KimKwangHoon If I try to use `useObserver`, it gives me the following error: Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. What I am doing is: `export const HomePage = useObserver(() => { //body })` – newbie Jan 26 '21 at 13:40
  • @newbie umm... Invalid use of useObserver. You need to write useObserver in return, not the part to be assigned. ``` import { useObserver, useLocalStore } from 'mobx-react' // 6.x or mobx-react-lite@1.4.0 function Person() { const person = useLocalStore(() => ({ name: 'John' })) return useObserver(() => (
    {person.name}
    )) } ```
    – KimKwangHoon Jan 27 '21 at 23:21