#Which type are the props supposed to be? Using Nextjs, Typescript, Supabase
6 messages · Page 1 of 1 (latest)
Couple of tips.
- Always capitalise your interfaces and types. Never use them as. uppercase.
- Always use lowercase for properties and methods
- You can use a type called
FCfrom react, which can take in a generic type:FC<MyProps>which will correctly assignMyPropsas the type of your component'sprops
eg.:
interface MyProps {
name: string
id: string
dob: string
}
const MyComponent: FC<MyProps> = props => {
// The following props will be available:
// props.name
// props.id
// props.dob
return // etc...
}
// More compact version:
const MyComponent: FC<MyProps> = ({ name, id, dob }) => {
return // etc...
}
- You can also use your interface and assign it as the type of your props:
interface MyProps {
name: string
id: string
dob: string
}
// More compact version:
const MyComponent: FC<MyProps> = ({ name, id, dob }: MyProps) => {
return // etc...
}
The type declaration is not right, your are saying that Home function will return profiles type
I think you meant to move the type assign inside the argument list:
function Home({ profiles }: profiles) {
// etc..
}
Sorry yes, you're right. typing out code on the phone is hard
I don't even know how you managed to create a snippet on the phone 😂
It just doesn't seem to work for me 😅
😄