wridgeu / sap-cap-solidjs

Playground to fiddle around with SAP CAP and SolidJS
The Unlicense
2 stars 0 forks source link

Learning: createResource #1

Closed wridgeu closed 1 year ago

wridgeu commented 1 year ago

https://www.solidjs.com/tutorial/async_resources https://www.solidjs.com/tutorial/async_suspense https://www.solidjs.com/docs/latest/api#createresource https://start.solidjs.com/core-concepts/data-loading

Data fetching and reactivity.

wridgeu commented 1 year ago

Lots of interesting concepts to explore. Same goes with all the state management / stores. You could also just make them global from the get-go and not use providers at all which was apparently a thing from React which people disliked.

wridgeu commented 1 year ago

I could use createResrouce for the general fetching of todos and reuse the created signal across the application. Upon changing (create/delete) a todo I could mutate the signal locally or, after having done the actual creation/deletion, use refetch to ... refetch everything.

Interesting example of this usage would be the general creation of the API layer here: https://github.com/solidjs/solid-realworld/blob/01f8e5961f8f5f2eb37160ddef12ba833f04637f/src/store/createAgent.js

and it's interaction with a "store" where createResource is actually used to wrap the API layer function and create a signal/state from it here: https://github.com/solidjs/solid-realworld/blob/01f8e5961f8f5f2eb37160ddef12ba833f04637f/src/store/createComments.js

wridgeu commented 1 year ago

As this app works for now and is simply a demo I won't rework the way it was written initially now but it certainly is an interesting concept thats worth exploring more. I myself really struggle with proper state management on client side anyway.