'id' does not exist in type 'UseTRPCMutationOptions<{ id: string; title?: string | undefined; ...
in pages/quest/[id].tsx
My router:
I've also tried setting types for const onSubmit = async (data: Type) => { with
Solution:Jump to solution
Hi, friend
I don't know if this will fix you problema but what you are doing here is very problematic:
```tsx
const onSubmit: SubmitHandler<QuestUpdateInput> = async (data) => {...
3 Replies
Solution
Hi, friend
I don't know if this will fix you problema but what you are doing here is very problematic:
Hooks should be called in a predictable order and in the main flow of your component function. In other words, do not call a hook inside a function, inside a if statement or inside a for statement..
You gotta try something like the following:
Thanks! Javascript sure has a way of doing things. I appreciate the help 🙏
You are welcome....
But @instancer_kirik , be mindful this is not a Javascript thing... this is a React thing.
If you are in the mood, I highly suggest you take a time to study how hooks work under the hood. Hooks shouldn't work, that's the catch. React deals with them in a very special way and that's why we always need to name our hooks starting with
use
, like useQuests
could be your custom hook.
Hooks have the power to persist data across renders.... that's not something common to functions, that's something common to classes and objects.
So in order for hooks to do what they do it's mandatory to call them always in the same order, usually on the top of your component ( which guarantees that ), but never on a conditional basis ( like inside a if
or a for
loop )
If you are using ESLint, I also recommend turning on the following rule:
It will show you an error if you try to use hooks in a scatchy way...
There are some ways of using hooks that this rule is not capable of saying it's valid, but of course if this rule says it's good and doesn't throw you an error... then you are for sure in a nice spot 🙂