S
SolidJS•10mo ago
tozz

Reactivity inside closure in return value

I have a function with a store, singals etc. This function returns an object, that object contains a function that is to be used as an event in the caller context. const { onSubmit } = someFunction() The definition of onSubmit inside someFunction
const onSubmit = (callback: (e: SubmitEvent) => void) => (event: SubmitEvent) => {
event.preventDefault();

// nodes are a store
Object.keys(nodes).forEach((key) => nodes[key].validate());

callback(event);
};
const onSubmit = (callback: (e: SubmitEvent) => void) => (event: SubmitEvent) => {
event.preventDefault();

// nodes are a store
Object.keys(nodes).forEach((key) => nodes[key].validate());

callback(event);
};
So the way you use it is <form onSubmit={onSubmit(() => { // my callback })} ...> This causes a lint error This function should be passed to a tracked scope (like createEffect) or an event handler because it contains reactivity, or else changes will be ignored. on the returning inner function. Likely very simple to fix, if I didn't need the closure for callback I could just store the inner function with createMemo, but I need the closure
3 Replies
tozz
tozz•10mo ago
Actally, now I'm wondering if the linter is wrong here The code seems to work just fine :
REEEEE
REEEEE•10mo ago
The linter isn't perfect. The code seems fine
tozz
tozz•10mo ago
@._rb Thanks for checking, I know the linter can give false positives, but I assumed I was in the wrong here, but manual testing shows that it works 🙂
Want results from more Discord servers?
Add your server
More Posts
Error [RollupError]: "assign" is not exported by "node_modules/solid-js/web/dist/server.js"When trying to build my solid-start app using `solid-start build` I get the following error: ``` fisolid-router not updating when going the same page but with different parameterso/ so i have this in `/routines/[id].tsx`: ```tsx export default function EditRoutine() { const updating a member inside another member inside an array inside a store using an indexo/ so i have data structured as follows, which is inside a store: ```js { actions: [ { FileRoutes duplicate hydration and not displaying dynamic routeif i used fileroutes the nested route is not working well, but if i used not fileroutes it behave How to use SolidStart on existing SolidJs project in order to benefit of File Based Routing ?PS: I use SolidJs only for SPA, so only client-side ? Is it possible to use SolidStart only for clieHow do I modify a member of an object in an array in a SolidJS Store using the SetStoreFunction?(Re-post from https://stackoverflow.com/questions/76843586/how-do-i-modify-a-member-of-an-object-in-useParams() not changing when switching pages?i'm getting really odd behavior ```tsx export default function EditRoutine() { const params = usComponent doesn't rerender when prop changesI have the component below: ```ts export default function FolderContents(props: { path: string }) { make object no longer reactiveo/ so i have this piece of code ```ts // routines: [] setRoutines(v => [...v, routine]) // routines:Solid Start errorhttps://damon.systems/projects When loading the page it gets loaded I ge tthis error saying l is nu