Merlin
Merlin
Explore posts from servers
SSolidJS
Created by Merlin on 8/8/2023 in #support
Refetching Route Data with Solid Router
Is there any way to refetch (revalidate) the data functions with @solidjs/router? (not Solid Start; I'm using Vite) - I'm mutating something on the backend and would like to make sure the data is up to date - Returning the whole createResource return value kind of works -- calling refetch correctly refetches the data, but mutate doesn't work. - Additionally, I'd like to refetch/revalidate all resources somehow. Is that possible?
115 replies
SSolidJS
Created by Merlin on 6/13/2023 in #support
Resource refetch doesn't trigger effect
I have this effect in my root layout (solid-start)
const user = useUser();
createEffect(() => {
console.log(user.name, user.email);
if (user.name) Crisp.user.setNickname(user.name);
if (user.email) Crisp.user.setEmail(user.email);
});
const user = useUser();
createEffect(() => {
console.log(user.name, user.email);
if (user.name) Crisp.user.setNickname(user.name);
if (user.email) Crisp.user.setEmail(user.email);
});
useUser:
function useUser() {
const [user, { mutate, refetch }] = createResource(() =>
api
.get<{
id: string;
role: "GUEST" | "USER";
email: string | null;
name: string | null;
teamId: string | null;
}>("/user/me")
.then((r) => r.data)
);

return {
refetch,
get email() {
return user()?.email;
},
get name() {
return user()?.name;
},
};
}
function useUser() {
const [user, { mutate, refetch }] = createResource(() =>
api
.get<{
id: string;
role: "GUEST" | "USER";
email: string | null;
name: string | null;
teamId: string | null;
}>("/user/me")
.then((r) => r.data)
);

return {
refetch,
get email() {
return user()?.email;
},
get name() {
return user()?.name;
},
};
}
When I call that refetch function from another component, I'd expect the effect in the 1st snippet to get re-run. Am I doing anything wrong?
20 replies