tRPCttRPC
Powered by
MugetsuM
tRPC•2y ago•
5 replies
Mugetsu

onError callback type

I want to have a callback onError passed from parent component to the child which has mutation call. onError should be passed directly to the mutation options but also accept plan Error type and undefined. But I struggle how to type it correctly.


export const DownloadTrigger = ({
  onError,
} {
  onError: ReactQueryOptions['batch']['triggerDownload']['onError'];  // This doesn't quire work is there more generic type or I should just add Error | undefined?
}) => {
  const downloadMutation = api.batch.triggerDownload.useMutation({
    onError,
  });

  useEffect(() => {
    handleFile()
      .catch((err: Error) => {
        // @ts-ignore
        onError(err);
      })
      .finally(() => {
        // @ts-ignore
        onError(undefined);
      });
export const DownloadTrigger = ({
  onError,
} {
  onError: ReactQueryOptions['batch']['triggerDownload']['onError'];  // This doesn't quire work is there more generic type or I should just add Error | undefined?
}) => {
  const downloadMutation = api.batch.triggerDownload.useMutation({
    onError,
  });

  useEffect(() => {
    handleFile()
      .catch((err: Error) => {
        // @ts-ignore
        onError(err);
      })
      .finally(() => {
        // @ts-ignore
        onError(undefined);
      });
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

How to access the request body in the onError callback?
Michael SchaufelbergerMMichael Schaufelberger / ❓-help
2y ago
How to get mutation onError typescript type
MugetsuMMugetsu / ❓-help
17mo ago
tRPC onError
JoeJJoe / ❓-help
3y ago
clear cookie onError
TkDodo 🔮TTkDodo 🔮 / ❓-help
4y ago