Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react router 6.4.3 typescript - useLocation any type error

How am i to fix the this any type error?

I tried passing custom type but that didn't work

like image 498
Opeyemi Avatar asked Dec 06 '25 04:12

Opeyemi


1 Answers

You can import Location from history. So update would be like this

import { Location } from "history";
const location = useLocation<Location>();

or alternatively you can create types

type LocationTypes = {
  pathname: string;
  state: any; //Here you can put your data type instead of any
  search: string;
  hash: string;
  key: string;
}

const location = useLocation<LocationTypes>();
like image 198
Evren Avatar answered Dec 08 '25 18:12

Evren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!