laksh
laksh
SSolidJS
Created by laksh on 8/16/2024 in #support
use createMemo outside a component
is it correct to use createMemo outside a component function? Can I use it in a util file? const getDataFromFirebase = (dataToFetch) => { try { if (firebaseDetails && Object.keys(firebaseDetails || {})?.length) { // some operations performed } } catch (error) { } }; The above fn is in a util file. In the above fn Object.keys(firebaseDetails || {}) is a very heavy computation since firebaseDetails is very large object. I want to memoise this. Is the below implementation correct? Since I am using createMemo outside the component in a util file and getDataFromFirebase is called from many places that's why it is placed in a util file. const memoizedFirebaseKeys = createMemo(() => Object.keys(firebaseDetails || {})); export const getDataFromFirebase = (dataToFetch) => { try { if (firebaseDetails && memoizedFirebaseKeys().length) { // some heavy computation } } catch (error) { } };
3 replies
SSolidJS
Created by laksh on 7/9/2024 in #support
web-vitals integration
Has anyone ever integrated https://www.npmjs.com/package/web-vitals with solidjs? Can anyone help me with the example of how to integrate this ?
29 replies
SSolidJS
Created by laksh on 7/1/2024 in #support
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`
18 replies