How to type react element arguments

I want to take a string like this
const Example = (guid : string) => { ... }
const Example = (guid : string) => { ... }
but when i call it like this it says
Type { guid: string; } is not assignable to type string
Type { guid: string; } is not assignable to type string
So i try to use an anonymous class kind of thing
const Example = ({guid : string}) => { ... }
const Example = ({guid : string}) => { ... }
But that's some mess. The following works
const Example = (input : {guid : string}) => { ... }
const Example = (input : {guid : string}) => { ... }
But that is ugly as hell, how do i write that properly ??
4 Replies
Xanacas
Xanacas2d ago
react components only have one "parameter" which is props. this means you need to use object connotations. Const example = ({guid, something_else}: {guid: string, something_else: string}) => { } or
Type PropsType= {guid: string, something_else: string} Const example = ({guid, something_else}: PropsType) => { }
Bored Student
Bored StudentOP2d ago
so
const Example = ({guid} : {string}) => { ... }
const Example = ({guid} : {string}) => { ... }
?
Xanacas
Xanacas2d ago
const Example = ({guid} : {guid:string}) => { ... }
Bored Student
Bored StudentOP16h ago
thats as annoying as the absence of named arguemnts
Want results from more Discord servers?
Add your server