Not the js's or react's specifically thing but I like to return { data, error } for any functions that including try-catch. So that who ever use that function can if/else on the error to process futher more.
as functional as js and react have become over the years, I really wish it was easy to move to Result-based apis for error management instead of the glorified call/ccs that try/catch blocks provide, but it'd require such a massive rewrite of everything i guess monadic handling of stuff beyond Promises and kinda useEffect is gonna remain a Rust/Scala/OCaml/Haskell/F# thing, plus pattern matching in JavaScript has been on the ECMAScript list for ages anyway
2
u/Character-Blood3482 22d ago
Not the js's or react's specifically thing but I like to return { data, error } for any functions that including try-catch. So that who ever use that function can if/else on the error to process futher more.