Create a helper function to call react-query mutation

44 Views Asked by At

I am using graphql-codegen with react-query to generate mutations like these.

const [createLogMutation, {}] = useCreateLogMutation({
  variables: {
    data: {
      logType,
      message,
      task
    }
  }
})

I want to create a helper function which handles the logging to database using this function. However, I am not able to use hook inside a plain function. What could be a good way to implement the helper function?

I want a simpler method like platformlogger.log(type, message, task) which would do the job. Without a helper function, I would have to call the above mutation everywhere I want to implement the logger.

0

There are 0 best solutions below