RepoPilot

How do their APIs compare?

About facebookexperimental/recoil · 2 messages · last activity 8/26/2026

Question

How do their APIs compare?

RepoPilot

Based on what's retrievable, here's how the two libraries' APIs compare in shape and purpose — these are fundamentally different kinds of libraries (a React state-management framework vs. a general-purpose utility library), so the comparison is more about design philosophy than overlapping functionality.

Recoil's API: declarative, graph-based state primitives for React

  • Core primitives are atom() and selector(), used as in [packages-ext/recoil-devtools/src/pages/Popup/useSelectionHooks.js:L13-L21], where an atom is created with a key and default, then consumed via the useRecoilState() hook — returning a [value, setter] tuple, mirroring React's useState convention but backed by a shared dependency graph instead of local component state.
  • The API surface is hook-centric (useRecoilState, and per the changelog, useRecoilCallback(), useRecoilRefresher_UNSTABLE()) rather than plain function calls — it's designed to be called from within React components/render or React-aware callbacks, not as standalone utility functions.
  • Recoil's API evolves with explicit "UNSTABLE" suffixes and documented breaking changes (e.g., selectors' get() and atoms' default accepting a Loadable, requiring selector.value()/atom.value() wrapping — noted in [CHANGELOG-recoil.md:L60-L64]), reflecting its experimental status. Version 0.5.0 also added atom effect lifecycle hooks like getLoadable(), getPromise(), getInfo_UNSTABLE() [CHANGELOG-recoil.md:L125-L140].
  • There's also a companion library, Refine, with its own distinct API for runtime type validation/refinement — e.g. jsonParser(array(object({num: number()}))) in [README-refine.md:L50-L66] — which is compositional/functional in style, closer to how lodash composes small functions, but scoped to type-checking rather than data manipulation.

Lodash's API: stateless utility functions over collections/values The retrieved chunks for lodash are mostly docs, perf benchmarks, and vendored third-party code (backbone.js, underscore, firebug-lite) rather than lodash's own source, but they still illustrate its API conventions:

  • Functions are pure, take data + config arguments, and return new values — e.g., _.intersectionBy(arrays, iteratee) documented in [doc/README.md:L1133-L1172], which accepts either a function or a "property shorthand" string ('x') as the iteratee.
  • The API is call-and-return, not hook- or subscription-based: _.isEqual(a, b), _.isArguments(x), etc., as exercised in the benchmark suites in [perf/perf.js:L1252-L1291] and [perf/perf.js:L1172-L1251] — no persistent state, no React dependency, usable in any JS environment.
  • Lodash supports a chainable wrapper style (seen conceptually in the vendored underscore/backbone code, e.g. _.each, .sort(), .pluck() methods in [vendor/backbone/backbone.js:L1017-L1056]), letting you compose multiple operations fluently on a wrapped value — a different composition model than Recoil's dependency-graph derivation via selector().

Key structural differences

  1. Statefulness: Recoil's atoms/selectors are inherently stateful and reactive (subscribing components re-render on change); lodash functions are stateless transformations with no subscription model.
  2. Environment coupling: Recoil's API only makes sense inside React (hooks require component context or Recoil-aware callback wrappers); lodash has zero framework coupling.
  3. Composition style: Recoil composes state via selector() derivations forming a dependency graph; lodash composes via function chaining or plain nested calls.
  4. Stability signals: Per the computed signals, Recoil's verdict is WAIT — Stale, last commit 2 years ago, and its OpenSSF Scorecard is 7.4/10 with weak Fuzzing/Token-Permissions/CII-Best-Practices — worth factoring in if choosing between the two for a new dependency, independent of pure API ergonomics. No equivalent scorecard/verdict data was provided for lodash in this session.

I don't have direct lodash core source (e.g. lodash.js intern

Want to ask your own question?

Open chat for facebookexperimental/recoil

Public Q&A. Generated by RepoPilot from the actual source of facebookexperimental/recoil. AI answers can be incomplete or stale — verify before relying on them.