Skip to main content
The @reatom/solid-js package provides seamless integration between Reatom and Solid.js, combining Reatom’s powerful state management with Solid’s fine-grained reactivity system.

Installation

This package is currently in alpha. The API is stable but may receive updates.

Setup

For SSR or isolated testing, provide the Reatom context to your Solid.js application:
For client-only applications, you can skip the provider and use the global stack frame.

Core APIs

useAtom

The primary hook for using Reatom atoms in Solid.js components:
API Reference:
Returns:
  • [accessor, setter]: Tuple containing:
    • accessor: Solid.js signal accessor for the atom’s state
    • setter: Optional setter function (undefined for computed atoms)
Features:
  • Automatic subscription management
  • Lazy subscription (only subscribes when accessed in tracking context)
  • Cleanup on component disposal
  • Full TypeScript support

withSolid Extension

Add a .solid property to atoms for direct access to Solid.js accessors:
Global Extension: Apply to all atoms automatically:
Now all atoms have a .solid property:

useFrame

Access the current Reatom frame:

Complete Examples

Counter with Computed Values

Todo List Application

Form with Validation

Using .solid Extension

TypeScript Support

Full TypeScript support with proper type inference:

Best Practices

1

Use useAtom for most cases

The useAtom hook provides the cleanest API for using atoms in Solid.js components.
2

Leverage withSolid for convenience

The .solid extension provides direct access to accessors without calling hooks.
3

Combine with Solid's primitives

Reatom atoms work seamlessly with Solid’s createEffect, createMemo, and other primitives.
4

Use computed atoms for derived state

Reatom’s computed atoms integrate perfectly with Solid’s fine-grained reactivity.

SSR and Testing

For server-side rendering or isolated tests, always provide a context:

Performance Characteristics

  • Lazy subscriptions: Atoms only subscribe when accessors are called in tracking contexts
  • Automatic cleanup: Subscriptions are cleaned up when components are disposed
  • Fine-grained updates: Only components that read changed atoms re-render
  • Cached accessors: The same accessor instance is reused across renders

Next Steps

  • Learn about Core Concepts for atoms and state management
  • Explore [Asynchttps://github.com/reatom/reatom/tree/main/packages for handling asynchronous operations
  • Check out [Formshttps://github.com/reatom/reatom/tree/main/packages for advanced form handling