DEV Community

Discussion on: Adding a service worker into your Next.js application

Collapse
 
kozkondev profile image
Konstantin Kožokar • Edited

Hi I suggest instead of listening window load event to use componentDidMount (or useEffect(, [])). It is more in react style.

Collapse
 
josedonato profile image
José Donato

if you see the source code i'm calling the window load inside useEffect but maybe it is redundant to have both the listener and useEffect :)

Collapse
 
riper profile image
Magnus Bondesson

Yes the window load listener is redundant and can be removed. I just tried this and everything loads correctly.

Thanks for this great hands-on tutorial!

Thread Thread
 
josedonato profile image
José Donato

Glad you liked it. Thanks for the input!