I'm creating a library which includes dependency of react-router-dom. There are some components in which I'm using react-router-dom NavLink, for example, let's name it Header -
Header.tsx
export const Header = () => (
<div>
<NavLink to="/home">Home</NavLink>
</div>
);
Bear in mind that this is just an example, to understand how I'm using the react-router-dom elements. So after building and publishing this library, I want to use it in my main react project, where I include this Header component and I have a parent BrowserRouter wrapper, so it looks something like this -
App.tsx
export const App = () => (
<BrowserRouter>
<Header />
</BrowserRouter>
);
But instead of rendering the page, it gives the following error:
Invariant failed: You should not use <NavLink> outside a <Router>
Any ideas what could be wrong and how to resolve this? React version is 16 in the parent project and v17 in the library. Router versions are 5.3.0 in both projects.
Could it be caused by the different react versions?