tRPCttRPC
Powered by
BillyBobB
tRPC•2y ago•
2 replies
BillyBob

Type '[]' has no properties in common with type 'MutateOptions<{ id: string....

Is it possible to get this to work? i am trying to make a single action that works across 2 routers.

const DeleteMedia = ({
  id,
  router,
}: {
  id: string
  router: keyof Pick<AppRouter, 'movieRouter' | 'serieRouter'>
}) => {
  const { refresh } = useRouter()
  const utils = api.useUtils()
  const deleteMedia = api[router].delete.useMutation({
    onSuccess: async (m) => {
      toast.success('Media Removed', { description: m.title })
      utils[router].list.invalidate()
      refresh()
    },
    onError: (error) => toast.error(error.message),
  })
  return (
    <form action={() => deleteMedia.mutate({ id })}> // Error here over deleteMedia
      <Button size="card" variant="card" type="submit">
        <XCircleIcon />
        Remove
      </Button>
    </form>
  )
}
const DeleteMedia = ({
  id,
  router,
}: {
  id: string
  router: keyof Pick<AppRouter, 'movieRouter' | 'serieRouter'>
}) => {
  const { refresh } = useRouter()
  const utils = api.useUtils()
  const deleteMedia = api[router].delete.useMutation({
    onSuccess: async (m) => {
      toast.success('Media Removed', { description: m.title })
      utils[router].list.invalidate()
      refresh()
    },
    onError: (error) => toast.error(error.message),
  })
  return (
    <form action={() => deleteMedia.mutate({ id })}> // Error here over deleteMedia
      <Button size="card" variant="card" type="submit">
        <XCircleIcon />
        Remove
      </Button>
    </form>
  )
}
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Type 'DecorateQueryProcedure<{ input: string; output: { id: string; name: string; }; transformer: fa
CarreinCCarrein / ❓-help
12mo ago
Type 'NextRequest' is missing properties from type 'NextApiRequest'
ForstoFForsto / ❓-help
3y ago
tRPC query has any type
KrishnaKKrishna / ❓-help
3y ago
Mongo Db Schema _id(ObjectId) in trpc get serializes to string
KubesKKubes / ❓-help
2y ago