How to call server function from client without the need of API
Answered
Maltese posted this in #help-forum
Original message was deleted.
20 Replies
Original message was deleted
not possible
Original message was deleted
Use server actions
Answer
Maltese
amm
not possible or use server actions?
@joulev Use server actions
Maltese
do you suggest me to use server actions when working with forms?
because that is not what I am talking about
I am tolking about a server function insede a onClick handler function
I think its the xy problem. https://xyproblem.info
Maltese
can I do something like this
import React from 'react'
import { handleClick } from '@/actoions/handleclick'
export default function Button() {
return (
<button onClick={async () => await handleClick()}>View stores nearby</button>
)
}'use server'
export const handleClick = ()=> {
console.log('heLLo world')
}@Maltese can I do something like this
It'll expose your secrets to the client
this is because code will be directly running in the browser
Maltese
man, I restarted my server and now its working like its expected haha
sorry for the questio here
@Anay-208 It'll expose your secrets to the client
Wrong. Code will run on the server
@Anay-208 It'll expose your secrets to the client
Maltese
I will not keep secrets in this action
yes, its server side, so my secrets will stay safe
ok tnx for the help