This function is a react hook for managing the state involved with loading data.
import { useLoadDataState } from '@oneblink/apps-react'const fetchData = async () => { const response = await fetch(`https://some-website.com/api?data=data`) if (!response.ok) { const text = await response.text() throw new Error(text) } return await response.json()}const MyComponent = () => { const [state, refresh, setResult] = useLoadDataState(fetchData) switch (state.status) { case 'LOADING': return <Loading /> case 'ERROR': return <Error message={state.error} /> case 'SUCCESS': // RENDER UI }}export default MyComponent Copy
import { useLoadDataState } from '@oneblink/apps-react'const fetchData = async () => { const response = await fetch(`https://some-website.com/api?data=data`) if (!response.ok) { const text = await response.text() throw new Error(text) } return await response.json()}const MyComponent = () => { const [state, refresh, setResult] = useLoadDataState(fetchData) switch (state.status) { case 'LOADING': return <Loading /> case 'ERROR': return <Error message={state.error} /> case 'SUCCESS': // RENDER UI }}export default MyComponent
The type of the data returned by your onLoad function
onLoad
The function that fetches your data. Should be a Promise that returns your data
This function is a react hook for managing the state involved with loading data.
Example