createMemo question

Is there any drawback to using createMemo for 'cheap' calls? Does the overhead, whatever it may be, make it not worth it for 'cheap' calls?
const inputError = createMemo(() => formCtx.errors[props.name]);

return (
<InputContext.Provider value={{}}>
<Field.Component>
<Field.Label
//unrelated props
/>
<Field.Input
//unrelated props
/>
<Show when={inputError()}>
<Field.Feedback msg={inputError()}/>
</Show>
</Field.Component>
)
const inputError = createMemo(() => formCtx.errors[props.name]);

return (
<InputContext.Provider value={{}}>
<Field.Component>
<Field.Label
//unrelated props
/>
<Field.Input
//unrelated props
/>
<Show when={inputError()}>
<Field.Feedback msg={inputError()}/>
</Show>
</Field.Component>
)
1 Reply
Madaxen86
Madaxen865mo ago
createMemo makes sense when you call the getter more than once like in your example inputError. The value gets only calculated once although it’s called twice. With a normal getter it would get called twice and depending on how many inputs you Fields you have , at some scale it will be a noticeable performance win to memo the value.
Want results from more Discord servers?
Add your server