I'm using localforage in a custom React hook that is meant to cache and return data. If data already exists, return it. If data doesn't exist, cache it and then return it. Before I was using a synchronous LRU library, but it seems the asynchronous nature of IndexedDB makes this a lot harder.
As of now, the custom hook is returning a promise with a resolved value that I need access to in one of my components. The data is right there, and yet I can't get to it. I've tried a mix of async/await, generators, and SE threads, but I suppose I'll use this snippet to post with.
Here's a condensed version of the component receiving the promise from the custom hook
const Component = ({ match }) => {
let data = useSuspenseFetch(match.params.id)
.then(res => {
console.log('need this', res)
return res
})
console.log('right here', data)
return <></>
}
export default Component
Is there any way to achieve this? I feel like I've gotten so close so many times, but there's always some pitfall.