i expect a refetch with new data when the value of "firma()" changes - but this don't work.
export function routeData({ params }) {
return createServerData$(
() => prisma.DP_T_Mitarbeiter.findMany({ where: { Betrieb: firma() } }),
{ key: () => ["DP_T_Mitarbeiter", firma()] }
);
}
What do i missing?
3 Replies
Where are you getting
firma
from? It's not declared in the routeDataIt‘s stored in an signal. To be exact: it seems to do a refetch but don‘t use the actual value
The signal is outside of the scope of the routeData, meaning it is in a global scope? If so, I would advise against it. It is considered dangerous to have "shared state" (in SSR, functions are called and thus create their own scope. But anything global is shared across all users)
If you want a dynamically updating result based on some user selection, I would probably go for an in-route resource which will refetch correctly based on a runtime value. You could also opt for a global Context instead which should be inserted in your
root.tsx
somewhere above your FileRoutes. With such a context you can access/manipulate a global state in routeData
functions on a per-user basis.