@21epub/use-rxjs-subject 中文文档教程
@21epub/use-rxjs-subject
带有 React Hooks 的 Rxjs 主题
Install
npm install --save @21epub/use-rxjs-subject
Usage
import React, { Component } from 'react'
import useRxjsSubject from '@21epub/use-rxjs-subject'
const Subject$ = new BehaviorSubject(0)
const TestFn1: React.FC = () => {
const [state] = useRxjsSubject(Subject$)
return <div>{state}</div>
}
const TestFn2: React.FC = () => {
const [state] = useRxjsSubject(Subject$)
return <div>{state}</div>
}
const App: React.FC = () => {
return (
<>
<TestFn1 />
<TestFn2 />
</>
)
}
有关详细信息:请参阅示例
Building and running on localhost
首先安装依赖项,然后为 parcel dev 安装 peerDeps:
npm install
npm run install-peers
在热模块重新加载模式下运行示例:
npm start
创建一个生产构建:
npm run build-prod
创建捆绑模块构建:
npm run build
Running
在浏览器中打开文件 dist/index.html
Testing
运行单元测试:
npm test
License
MIT © 加里
@21epub/use-rxjs-subject
Rxjs Subject with React Hooks
Install
npm install --save @21epub/use-rxjs-subject
Usage
import React, { Component } from 'react'
import useRxjsSubject from '@21epub/use-rxjs-subject'
const Subject$ = new BehaviorSubject(0)
const TestFn1: React.FC = () => {
const [state] = useRxjsSubject(Subject$)
return <div>{state}</div>
}
const TestFn2: React.FC = () => {
const [state] = useRxjsSubject(Subject$)
return <div>{state}</div>
}
const App: React.FC = () => {
return (
<>
<TestFn1 />
<TestFn2 />
</>
)
}
For Details: See Example
Building and running on localhost
First install dependencies and then install peerDeps for parcel dev:
npm install
npm run install-peers
To run Example in hot module reloading mode:
npm start
To create a production build:
npm run build-prod
To create a bundle module build:
npm run build
Running
Open the file dist/index.html
in your browser
Testing
To run unit tests:
npm test
License
MIT © garry