Paradinio
Derrived Signal With A Ressource
Hi!
That might be an easy one.
I get a resource from a Context called userData.
What is the proper way to derrive further signals or just values from it? The following example doesn´t seem correct and I think it smells.
const {userData: [user]} = useAuth("");
// When the component renders, user is not defined yet.
const [userInitials, setUserInitials] = createSignal<string>("");
createEffect(() => {
if(user.state === "ready") {
// as soon user is there, I set the initials-signal.
setUserInitials(user().firstName.slice(0, 1) + user().lastName.slice(0, 1));
}
})
7 replies
How to implement a simple search-button?
We are quite new to solid, so a big sorry, if this question is repetitive, but I was not able to find a satisfying answer to our problem, yet.
There are some controlled input-fields like selects, etc. which are stored / managed in a createStore and provided via a createContext.
Those values have to be used in a fetch-function as query-params.
My initial thought was to use createResource to manage the data, and use those reactive values as a source.
There are two problems to this solution:
1. The fetcher-function is called on mount, or when it is rendered or whatever. We do not want this. The user has to initiate the fetching.
2. As soon something changes in the input fields, or let´s say, the user changes his filter settings, the data is refetched again. We do not want this. The user has to explicitly press "Show Results" again before we trigger a refetch.
I´ve built up a little example, without the store etc. as it is not part of the question.
It can be found on this playground:
https://playground.solidjs.com/anonymous/d80fb752-2732-4d65-a141-86bca13d95e8
Hope someone can help, with that!
Cheers,
Levin
6 replies