Effect CommunityEC
Effect Community2mo ago
3 replies
LiquiFruit

Running Logic Before Setting an Atom Value in Effect Typescript

Whats the correct way to run an effect as the set() function returned from useAtom?

Basically I want to run logic before setting the value: check that a tip % is non-negative for instance.

I know I can write this logic in a wrapper function:
const trySet = (tip) => if (tip >= 0) set(tip)
but it seems like the correct way to do this would be to construct the atom from an effect or atom.fn
Was this page helpful?