0.1.3 • Published 2 years ago

recoil-object v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Recoil-Object

Manage related atoms just like object

Manage related atoms just like object

Features

  • Manage related atoms just like object

Example

// without root atom

import { recoilObject, RecoilObjectDefault, recoilObject } from 'recoil-object'

type Info = {
  id: string
  profile: {
    name: string
    age: number,
  }
}

const infoDefault: RecoilObjectDefault<Info> = {
  id: 'default-id',
  profile: {
    name: 'my-name',
    age: 1,
  },
}

/*
  const infoAtom = {
    id: RecoilState<string>,
    profile: {
      name: RecoilState<string>,
      age: RecoilState<number>
    }
  } 
*/
export const infoAtom = recoilObject({
  key: 'my-info',
  default: infoDefault,
})
// with root atom (require recoil-nexus)

import { recoilObject, RecoilObjectDefault, recoilObjectWithRoot } from 'recoil-object'

type Info = {
  id: string
  profile: {
    name: string
    age: number,
  }
}

const infoDefault: RecoilObjectDefault<Info> = {
  id: 'default-id',
  profile: {
    name: 'my-name',
    age: 1,
  },
}

/*
  const infoAtom = {
    _self: RecoilState<{
      id: string,
      profile: {
        name: string,
        age: number
      }
    }>
    id: RecoilState<string>,
    profile: {
      _self: RecoilState<{
        name: string,
        age: number
      }>
      name: RecoilState<string>,
      age: RecoilState<number>
    }
  } 
*/
export const infoAtom = recoilObjectWithRoot({
  key: 'my-info',
  default: infoDefault,
})

License

MIT

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago