FunctionuseLoadDataEffect

  • This function is a react hook for loading data and reloading it with a way of aborting the request. Useful when using reducers to load data asynchronously and store the state outside of this react hook.

    import { useLoadDataEffect } from '@oneblink/apps-react'

    const fetchData = async (abortSignal) => {
    const response = await fetch(
    `https://some-website.com/api?data=data`,
    {
    signal: abortSignal,
    },
    )

    const data = await response.json()
    // store data in a data layer for later use
    }

    export default function MyComponent() {
    const handleRefresh = useLoadDataEffect(fetchData)

    return <button onClick={handleRefresh}>Refresh</button>
    }

    Parameters

    • onLoad: ((abortSignal: AbortSignal) => void)

      The function that fetches your data and stores it for later use.

        • (abortSignal): void
        • Parameters

          • abortSignal: AbortSignal

          Returns void

    Returns (() => void)

    A function to reload the data

      • (): void
      • Returns void