Modifying Signals Returned by createAsync in SolidJS: Best Practices and Alternatives
In SolidJS (using the SolidStart framework), how can I modify the signal returned by createAsync? For example, in a scenario where I use createAsync to fetch data from an API and load it into an editor or textarea, then after making modifications, I want to save the updates via an Action by calling another API. The parameter passed to the Action would be the modified data based on what was initially fetched by createAsync.
I checked the documentation but couldn’t find a way to modify the signal from createAsync. So I came up with two possible solutions:
1. Use createResource;
2. Create another signal B, then use onMount to set signal B based on the final value of the signal from createAsync. To ensure that signal B is only set after the createAsync value is resolved, the current component would be wrapped in a Suspense component, ensuring other parts are rendered only after the async data is loaded.
Is my approach correct? Additionally, the documentation mentions that createAsync is a lightweight version of createResource and will become a primitive in Solid 2.0. Does this mean that createAsync is more recommended for use?
thanks
I checked the documentation but couldn’t find a way to modify the signal from createAsync. So I came up with two possible solutions:
1. Use createResource;
2. Create another signal B, then use onMount to set signal B based on the final value of the signal from createAsync. To ensure that signal B is only set after the createAsync value is resolved, the current component would be wrapped in a Suspense component, ensuring other parts are rendered only after the async data is loaded.
Is my approach correct? Additionally, the documentation mentions that createAsync is a lightweight version of createResource and will become a primitive in Solid 2.0. Does this mean that createAsync is more recommended for use?
thanks
