How to enter props in React TypeScript? I'm getting the error Property 'authors' does not exist on type '[Props] & {children?: ReactNode;'}'.ts. I'm expecting to be passed an array consisting of name and password keys.
https://codesandbox.io/s/test-login-page-tasks-24-04-forked-eg91s5?file=/src/components/Login.tsx:229-274
type Props = { authors: { name: string; password: string; }[]; }; const Login: FC<[Props]> = ({ authors }) => { return ( ... ) }
, even though I'm passing props.
You define the IUser interface using the IUser type and define the name, password status, which will cause problems because when you define this:
This is wrong because name, password is a string, so try defining it like this:
Then you have to fix passing the author to the FC component:
The last thing you have to fix this type to match the data type passed from App.tsx:
and you pass it from your application like this:
Try changing
[Props]
toProps
as shown belowNow it works because it requires an object instead of an array, we will pass an object like
<Loginauthors={authors} />
. Now, the author will be an array of objects.