Is it possible to pass paramters a function wrapped by a createEffect/createMemo?

,I have a certain function in my component which I have noticed runs multiple times since I am referencing the function multiple times in my JSX. I found that the recommended way to alleviate this problem is to wrap the function in a createMemo. However my function requires some parameters which are passed to it through its calling context. So is there any way I can pass parameters to a function wrapped by a useEffect or useMemo?
1 Reply
Martnart
Martnart10mo ago
If the parameters themselves are reactive you should just declare them as signals and have the memo listen to them:
const [param] = createSignal()

const value = createMemo(() => {
const theParam = param()
// doSomeThingWithParam()
}
const [param] = createSignal()

const value = createMemo(() => {
const theParam = param()
// doSomeThingWithParam()
}
If they are static you could do something like this:
const getMemo = (param) => createMemo(() => {
return (someSignal() || someComputation()) + param
}
const getMemo = (param) => createMemo(() => {
return (someSignal() || someComputation()) + param
}