.hatulapro
.hatulapro
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Revaycolizer on 4/19/2023 in #questions
Passing data as props in form function
You can create the handler function with another function:
const handler = (data: whatever) => {
return (e: React.FormEvent) => {
// stuff
}
}
const handler = (data: whatever) => {
return (e: React.FormEvent) => {
// stuff
}
}
Or define it inline (if possible):
<button onClick={(e: React.FormEvent) => console.log(someData)}></button>
<button onClick={(e: React.FormEvent) => console.log(someData)}></button>
12 replies
TTCTheo's Typesafe Cult
Created by fotoflo on 2/20/2023 in #questions
should i just make a REST api for that?
useQuery doesn't call the server on every render. It only calls when it "needs" to (depending on how you configure it). But if you only want to make a request on an event, that's what useMutation is for
9 replies
TTCTheo's Typesafe Cult
Created by Chadbek on 1/15/2023 in #questions
Modularized Imports
You can't customize it too much, but {{ kebabCase member }} should do the trick
4 replies
TTCTheo's Typesafe Cult
Created by WOLG on 1/10/2023 in #questions
Benefits of NextPage type
NextPage allows you to set getInitialProps on your page (https://nextjs.org/docs/api-reference/data-fetching/get-initial-props). Passing a generic type to it will also force getInitialProps to return that type.
const Page: NextPage<{x: number}> = ({ x }) => (
<main>{x} is a number</main>
)

Page.getInitialProps = () => {
// If this doesn't return an object of type {x: number} TS will show an error
return { x: 9001 }
}
const Page: NextPage<{x: number}> = ({ x }) => (
<main>{x} is a number</main>
)

Page.getInitialProps = () => {
// If this doesn't return an object of type {x: number} TS will show an error
return { x: 9001 }
}
It probably doesn't matter if you're not using getInitialProps though. Personally I just use it to make it clear that a component a page
2 replies
TTCTheo's Typesafe Cult
Created by Prabhath on 1/5/2023 in #questions
Can anyone share how to infer type of class member of trpcresponse
Try wrapping it with NonNullable to only refer to the object you're returning
NonNullable<RouterOutputs['abc']['def']>['someMember']
NonNullable<RouterOutputs['abc']['def']>['someMember']
9 replies
TTCTheo's Typesafe Cult
Created by Prabhath on 1/5/2023 in #questions
Can anyone share how to infer type of class member of trpcresponse
You can simply do:
RouterOutputs['abc']['def']['someMember']
RouterOutputs['abc']['def']['someMember']
9 replies
TTCTheo's Typesafe Cult
Created by Knox on 12/31/2022 in #questions
Get session data inside a mutation
It probably doesn't apply in this case, but you can still access ctx.session?.user in public procedures, just make sure the user is not undefined. It can be useful in some situations
19 replies
TTCTheo's Typesafe Cult
Created by Leke on 11/27/2022 in #questions
'paginationRange.length' is possibly 'undefined'.ts(18048)
when paginationRange is falsey, paginationRange.length returns undefined as well. Then you are comparing undefined to a number, which doesn't make sense (JS will always return false, but TS does not allow that comparison).
4 replies
TTCTheo's Typesafe Cult
Created by Simvolick on 11/23/2022 in #questions
No Overload matches this call with nextAuth mapping
providers can be null which would throw an error
3 replies
TTCTheo's Typesafe Cult
Created by taco is a friend of bluey 🇵🇸🏴 on 10/22/2022 in #questions
Getting an error saying `TypeError movies.map is not a function`
Did you make sure to pass the props to your component? In _app.tsx you should have something like this:
<Component {...props} />
<Component {...props} />
9 replies