In one of my components in a React npm module library, I need to alert the user about unsaved changes.
Which means, I have to do it onComponentUnmount.
I have found results, and the only possible way of doing that is through using a router (using like or setRouteLeaveHook, as SPA doesn’t seem to call the JS event listener – beforeunload
Since npm modules don’t really own the components (the React projects using those modules own it), doing anything related to Router seem to yield to the error as shown below:
Error: Invariant failed: You should not use "anything-router-related" outside a <Router>
Is there any way to alert the user about unsaved changes without using react-router in a React npm module library? Or else how to properly use react router in a react npm module library?