SolidJSS
SolidJS2y ago
17 replies
laksh

I have a use case for createResource vs normal async await api call.

`const sendOtp = async({reqId}) => { return await sendApiRequest({ endpoint: "generateotp", data: { reqId, }, method: "post", }); };


sendApiRequest: It is just an async function calling an api to get otp and it is returning a promise

this sendOtp gets called on a button press and i am calling the api with the help of sendApiRequest

Now I want to know the recommended approach to trigger the sendApiRequest function. Is this the correct approach or
shall I call the api with the help of createResource and pass an async fetcher function sendApiRequest where async fetcher function will return the
signal which I don't think I need it and since that will be called only in createEffect and I dont have that case.
Please tell me the best approach to solve such cases`
Was this page helpful?