jxom / react-loads

React Loads is a backend agnostic library to help with external data fetching & caching in your UI components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use this library with class components (resources etc)?

CarlQLange opened this issue · comments

Hey,

Thanks for the useful library.

My application is made up mostly of class components, and unfortunately hooks don't work within class components. I'm wondering how best to use this library, particularly the caching/resources functionality, with class components.

Thanks!

commented

Hey! Glad to hear you've found it useful.

You can sure use React Loads with class components! Check out the example of Render Props Usage. The Render Props version of React Loads also shares the same API as the useLoads hook.

<Loads load={fn} {...props}> === useLoads(fn, props)

However, Resources are not yet supported with class components, as they only provide you with useLoads hooks. If there is more interest in class component usage for resources, I'll consider building it. But I also encourage PRs if anyone wants to build that implementation.

OK, thanks! Unfortunately I'm still a beginner with React - perhaps if you could give a breakdown of what you think would need doing for that implementation, I could give it a go! Resources seems useful mostly due to the built-in caching, but I like the paradigm in general. It seems that passing context will do for now!