@rcp/use.behaviorsubject
v1.2.3
Published
use hook for rxjs behavior subject
Downloads
60
Readme
@rcp/use.behaviorsubject
use hook for rxjs behavior subject
Installation
npm install @rcp/use.behaviorsubject
# or use yarn
yarn add @rcp/use.behaviorsubject
Usage
useBehaviorSubject
import { BehaviorSubject } from 'rxjs'
import { useBehaviorSubject } from '@rcp/use.behaviorsubject'
const subject = new BehaviorSubject({ name: 'imcuttle' })
const App = () => {
const [data, setData] = useBehaviorSubject(subject)
}
createReactBehaviorSubject
import { createReactBehaviorSubject } from '@rcp/use.behaviorsubject'
const { subject, useSubject } = createReactBehaviorSubject({ name: 'imcuttle' })
const App = () => {
const [data, setData] = useSubject()
}
useStateToSubject
React state pipe to subject, and subject effects to state
import { BehaviorSubject } from 'rxjs'
import { useStateToSubject } from '@rcp/use.behaviorsubject'
const { subject, useSubject } = createReactBehaviorSubject({ name: 'imcuttle' })
const userSubject = new BehaviorSubject({})
const App = () => {
const [user, setUser] = React.useState({ name: 'imcuttle' })
useStateToSubject([user, setUser], userSubject)
}
API
Related
Authors
This library is written and maintained by 余聪, [email protected].
License
MIT