Reputation: 15303
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.
Upvotes: 1
Views: 2050
Reputation: 15303
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!!
Upvotes: 5