You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just helped a friend debug an issue with his first foray into Solid. The root of the issue was that he passed a non-signal value into createResource which lead to it not being reactive. The solution was wrapping it in a function. This seems like an easy enough mistake to make (and thus timesink) that we were wondering why there is not a separate function for non-signal values e.g. createStaticResource?
import{createResource}from"solid-js";import{useParams}from"@solidjs/router";asyncfunctionfetchUser(id){constresponse=awaitfetch(`https://jsonplaceholder.typicode.com/users/${id}`);returnresponse.json();}constUser=()=>{constparams=useParams();const[data]=createResource(params.id,fetchUser);// Pass the id parameter to createResourcereturn(<div><Showwhen={!data.loading}fallback={<p>Loading...</p>}><div><p>Name: {data().name}</p><p>Email: {data().email}</p><p>Phone: {data().phone}</p></div></Show></div>);};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I just helped a friend debug an issue with his first foray into Solid. The root of the issue was that he passed a non-signal value into
createResource
which lead to it not being reactive. The solution was wrapping it in a function. This seems like an easy enough mistake to make (and thus timesink) that we were wondering why there is not a separate function for non-signal values e.g.createStaticResource
?The mistake is so easy to make, that it even made its way into the official docs [here] (and here is the PR to fix it):(https://docs.solidjs.com/guides/routing-and-navigation#accessing-parameters):
Beta Was this translation helpful? Give feedback.
All reactions