import { useMutation , UseMutationOptions , UseMutationResult , } from "react-query" ; import { DatabaseReference , remove , runTransaction , set , setWithPriority , TransactionOptions , TransactionResult , update , } from "@firebase/database" ; export type UseDatabaseSetMutationOptions = { priority ? : string | number | null ; } ; export function useDatabaseSetMutation < T = unknown > ( ref , options ? , useMutationOptions ? ) { return useMutation < void , Error , T > ( ( value ) => { if ( options ?. priority !== undefined ) { return setWithPriority ( ref , value , options . priority ) ; } return set ( ref , value ) ; } , useMutationOptions ) ; } type UpdateValues = Record < string , unknown > ; export function useDatabaseUpdateMutation < T extends UpdateValues = UpdateValues > ( ref , useMutationOptions ? ) { return useMutation < void , Error , T > ( ( values ) => { return update ( ref , values ) ; } , useMutationOptions ) ; } export function useDatabaseRemoveMutation ( ref , useMutationOptions ? ) { return useMutation < void , Error , void > ( ( ) => { return remove ( ref ) ; } , useMutationOptions ) ; } export function useDatabaseTransaction < T = any > ( ref , transactionUpdate , options ? , useMutationOptions ? ) { return useMutation < TransactionResult , Error , void > ( ( ) => { return runTransaction ( ref , transactionUpdate , options ) ; } , useMutationOptions ) ; }