Home > database >  react router 6.4.3 typescript - useLocation any type error
react router 6.4.3 typescript - useLocation any type error

Time:11-21

How am i to fix the this any type error?

I tried passing custom type but that didn't work

CodePudding user response:

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>();

CodePudding user response:

I've been able to resolved it, I checked the node_module for the type and I saw it there. It is the same as the type LocationTypes @Evren suggested so I restarted my system and it works fine now, didn't know why it wasn't detected without having to restart my system

  • Related