Skip to content

Commit c95946c

Browse files
committed
Refresh ovbservable on dependency change
1 parent ab1bea4 commit c95946c

File tree

3 files changed

+11558
-25
lines changed

3 files changed

+11558
-25
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ declare function useObservable<State, Inputs>(
8888
inputFactory: InputFactory<State, Inputs>,
8989
initialState: State,
9090
inputs: RestrictArray<Inputs>,
91+
deps: readonly any[],
9192
): State
9293
```
9394

@@ -183,6 +184,30 @@ function App() {
183184
ReactDOM.render(<App />, document.querySelector('#root'))
184185
```
185186

187+
**Refresh ovbservable on dependency change**
188+
189+
```tsx
190+
import React from 'react'
191+
import ReactDOM from 'react-dom'
192+
import { useObservable } from 'rxjs-hooks'
193+
import { from } from 'rxjs'
194+
import { map, take } from 'rxjs/operators'
195+
196+
function App(props: { foo: number }) {
197+
const value = useObservable(() => from([1, 2, 3, 4]).pipe(
198+
map(val => val + props.foo)
199+
), 200, [props.foo])
200+
return (
201+
// render four times
202+
// 2, 4, 5, 6
203+
<h1>{value}</h1>
204+
)
205+
}
206+
207+
ReactDOM.render(<App foo={1} />, document.querySelector('#app'))
208+
ReactDOM.render(<App foo={2} />, document.querySelector('#app'))
209+
```
210+
186211
### `useEventCallback`
187212

188213
```tsx

0 commit comments

Comments
 (0)