0.1.3 • Published 2 years ago
recoil-object v0.1.3
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