0

I tried so many ways to make it works, but right now I'm staying in this same place.

How I can bypass this? Why this is not works properly?

    import React, { useEffect, useState } from "react";
import { withRouter } from "react-router-dom";
import axios from "axios";
import Stories from "./layouts/Stories";
import Loader from "./layouts/Loader";

export default withRouter(News);

Error:

ERROR in ./src/components/News.js 178:21-31
export 'withRouter' (imported as 'withRouter') was not found in 'react-router-dom' (possible exports: BrowserRouter, HashRouter, Link, MemoryRouter, NavLink, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, createSearchParams, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, unstable_HistoryRouter, useHref, useInRouterContext, useLinkClickHandler, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams)

I know the problem is the version, but how I can make this works?

DejMon
  • 3
  • 1
  • Which version of `react-router-dom` are you using? Based on the error message, I think it's v6. `withRouter` is removed in v6 – mc-user Jun 30 '22 at 11:42
  • https://stackoverflow.com/questions/71097375/how-can-i-use-withrouter-in-react-router-v6-for-passing-props – razer Jun 30 '22 at 11:43

1 Answers1

0

According to the ReactRouter's documentation, you should use the following import statement instead of the one you have:

import { withRouter } from "react-router";

Do make sure that have the React Router package installed, as react-router and react-router-dom are not the same package

Zejj
  • 66
  • 1
  • 5