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>} Copy
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>}
The function that fetches your data and stores it for later use.
A function to reload the data
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.
Example