'Property 'background' does not exist on type 'unknown'. ReactJS/useHistory()
I'm getting this error Property 'background' does not exist on type 'unknown'.ts(2339), when I try to use this code
const location = useLocation();
const background = location.state && location.state.background;
I imported all of the needed functions from react-router-dom
import {
Redirect,
Route,
RouteComponentProps,
Switch,
useLocation,
withRouter,
} from "react-router-dom";
I'm using class component if it does matter.
I will be very grateful if you could give me some tips.
Solution 1:[1]
import {Location} from "history";
const location = useLocation<{background?: Location<{} | null | undefined>}>();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alexander |