Write a generic React Suspense Resource factory

Kent C. Dodds
InstructorKent C. Dodds

Share this video with your friends

Send Tweet

Using Suspense within our component isn't exactly ergonomic. Let's put all that logic into a reusable function so we can create resources anytime we need them and for any asynchronous interaction in our app.

Stephen James
Stephen James
~ 5 years ago

I saw this description of the createResource in another video, but your refactoring from a specific pokeman fetch to a generic resource fetch really got the concept across! Thanks KCD

Viktor Soroka
Viktor Soroka
~ 5 years ago

Great stuff, I think for a createResource function would be better to pass a promise rather than a function, so createResource won't be obliged with managing the invocation of the passed-in function.

cognivore
cognivore
~ 3 years ago

FYI, none of the code samples work anymore because Could not find module in path: 'react/jsx-runtime' relative to '/src/app.js'