XYOracleNetwork/sdk-xyo-react-js

View on GitHub
packages/sdk/packages/indexed-results/src/hooks/useTriggerFreshIndexedResult.tsx

Summary

Maintainability
A
45 mins
Test Coverage
import { useCallback } from 'react'

import type { IndexedResultsConfig } from '../interfaces/index.ts'

export const useTriggerFreshIndexedResult = (indexedResultsConfig?: IndexedResultsConfig, trigger?: boolean) => {
  const { processIndexedResults, refresh } = indexedResultsConfig ?? {}

  const freshResult = useCallback(async () => {
    if (refresh && trigger) {
      return refresh ? await refresh?.(processIndexedResults ?? {}) : undefined
    }
  }, [refresh, processIndexedResults, trigger])

  return freshResult
}