'interface locationProps, Expected 0 type arguments, but got 1
I am passing a user object through the useNavigation object like:
let navigate = useNavigate();
const showUser = (user: UserProp): void => {
navigate('view', { state: user });
}
once i landed to the view component, I am trying to get the value from the location. but getting error.
here is the code :
interface locationProps {
state: { user: UserProp }
}
export default function UserView() {
const { state } = useLocation<locationProps>();
return (
<h1>{state && state.user.name}</h1>
)
}
getting an error as interface locationProps, Expected 0 type arguments, but got 1.
Solution 1:[1]
It works for me:
export interface UserProp {
id: number;
name: string;
username: string;
email: number;
address: AddressProps
}
after the declaration of the interface i used the same as:
const data = useLocation().state as UserProp; to get my all data.
thanks every one!!
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 | 3gwebtrain |
