UNPKG

@lido-sdk/react

Version:

This project is being slowly deprecated and may not receive further updates. Check out [modern Lido SDK](https://github.com/lidofinance/lido-ethereum-sdk/pulls) to access latest functionality. It is actively maintained and is built for interacting with Li

39 lines (36 loc) 1.13 kB
import { useCallback } from 'react'; import useSWRSource from 'swr'; import { useSDK } from './useSDK.js'; const LIDO_SWR_DEFAULT_CONFIG = { errorRetryInterval: 10000, focusThrottleInterval: 10000, }; const useLidoSWR = (key, fetcher, config) => { const { swrConfig } = useSDK(); const result = useSWRSource(key, fetcher, Object.assign(Object.assign(Object.assign({}, LIDO_SWR_DEFAULT_CONFIG), swrConfig), config)); const mutate = result.mutate; const update = useCallback(() => { return mutate(undefined, true); }, [mutate]); return { mutate, update, /* * support dependency collection * https://swr.vercel.app/advanced/performance#dependency-collection */ get data() { return result.data; }, get loading() { return result.isValidating; }, get initialLoading() { return result.data == null && result.isValidating; }, get error() { return result.error; }, }; }; export { useLidoSWR };