3gwebtrain
3gwebtrain

Reputation: 15303

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.

Upvotes: 1

Views: 2050

Answers (1)

3gwebtrain
3gwebtrain

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

Related Questions