SolidJSS
SolidJSโ€ข3y agoโ€ข
3 replies
chiefcll

Solid Router with useParams, createResource and two params

I've got a dynamic page with two params in the url needed by createResource to make it's data call.

const params = useParams();
 
 const [data] = createResource(params, provider.getInfo);

This works for the initial request, but if I navigate to same dynamic route with different params, it won't refetch the data. I assume this is due to params being a 'store' and doesn't trigger anything unless the properties are accessed.

The following does work but isn't pretty:
const params = useParams();
 // Need the reactivity and sending two params
  function paramsWrapper() {
    return {
      id: params.id,
      type: params.type
    }
  }

  const [data] = createResource(paramsWrapper, provider.getInfo);


I'd like to get rid of the paramsWrapper. Any way to turn params into a signal?
Was this page helpful?