@reatom/npm-solid-js
TypeScript icon, indicating that this package has built-in type declarations

3.6.0 • Public • Published

This is the binding for the Solid view framework. The reason to use these bindings is the Reatom ecosystem. We have a lot of packages and helpers to handle basic UI logic, including network caching, data persistence, and complex flow description.

Installation

npm i @reatom/npm-solid-js

Also, you need to be installed @reatom/core or @reatom/framework and solid-js.

Read the core docs first for production usage.

Usage

Setup reatomContext

The first time, you need to add the Reatom provider to the root of your application.

import { createCtx, connectLogger } from '@reatom/framework'
import { reatomContext } from '@reatom/npm-solid-js'

const ctx = createCtx()
connectLogger(ctx)

render(
  () => (
    <reatomContext.Provider value={ctx}>
      <App />
    </reatomContext.Provider>
  ),
  document.getElementById('root')!,
)

useAtom hook

Now you will be able to use Reatom hooks.

import { atom } from '@reatom/framework'
import { useAtom } from '@reatom/npm-solid-js'

const CountingComponent = () => {
  const [count, setCount] = useAtom(countAtom)

  return (
    <div>
      Count value is
      <button onClick={() => setCount((c) => c + 1)}>{count()}</button>
    </div>
  )
}

useCtx hook

If you need to get the ctx from the context, you could use the shortcut hook useCtx. With ctx in the component body, you can manipulate subscriptions more flexibly with Solid's onMount, onCleanup, and so on.

Package Sidebar

Install

npm i @reatom/npm-solid-js

Weekly Downloads

2

Version

3.6.0

License

MIT

Unpacked Size

29.9 kB

Total Files

11

Last publish

Collaborators

  • artalar