Best way how to call sever function onClick (SOLVED)
Hi iam just playing with solid but still cant find best way how to call server side action from simple onClick.
I can use API url to call it there i can prepare data and return them.
But i think there must be something better?
13 Replies
Are you talking about a server function or a server action?
A server action you add to a form like <form action={some FormAction}
Hi thanks for reply basically what i need to do is
<button onClick={onClickHandler}>fetch</button>
const onClickHandler = () => {
//call server function that returns signed request parameters
// setStore(createResource(parametersFromServerFunction, async() => {await fetch ....})
}
something like this. since iam on router 0.8.5 i dont have actions available when i try updat to 0.10.5 I get TypeError: Comp is not a function
my dependencies
"dependencies": {
"@solidjs/meta": "^0.29.3",
"@solidjs/router": "^0.10.5",
"solid-js": "^1.8.7",
"solid-start": "^0.3.10"
}
}
i tried every single approach but still cant make this work
awww i used really old solidjs start 😦
yeah solid-start 0.4 changes a bunch of stuff
I think the new router (
v0.10.x
) is not compatible with solid-start v0.3.x
If you want to use it you'll have to upgrade to 0.4.x
yes router 0.4.x makes things really easy and straight forward
So you got things figured out?
olk giving this up will try qwik if there is better doc or will make esy api routes.
simple thing how to get data from server when i need it. page load / click button.
this gives me "AA" output server / client
and console error
caught (in promise) Error: Hydration Mismatch. Unable to find DOM nodes for hydration key: 0-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-4-0
@brenelzit should be "use server" instead of "user server"
f......... so stupid misstake
Last attempt
All works nice but when i hit button AA i can see i send request it returns right data but s signal is undefined.
thanks for helping
Return value from createAsync is already a signal I think
yes but when i want refresh / call load more items on click i need mutate this signal. and yes its accessor
Can't this be done much more simply just using
createResource
and calling the server function directly, ignoring the action apis since you're not doing a form submission or anything?
^^^ yes this is it . dont realized i can call fucntion directly from resource. But what i missed is REFRESH !!! function thats the big one. Thanks againg for helping.