#Which type are the props supposed to be? Using Nextjs, Typescript, Supabase

6 messages · Page 1 of 1 (latest)

kindred geyser
#

I'm trying to figure out what type my props have to be.
I posted the code attached

weak wigeon
#

Couple of tips.

  1. Always capitalise your interfaces and types. Never use them as. uppercase.
  2. Always use lowercase for properties and methods
  3. You can use a type called FC from react, which can take in a generic type: FC<MyProps> which will correctly assign MyProps as the type of your component's props
    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...
}
  1. 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..
}
vagrant spindle
weak wigeon
vagrant spindle
#

😄