Skip to content
Permalink
Browse files

feat: Use useObservable

  • Loading branch information...
atomita committed Oct 26, 2019
1 parent 86d5d07 commit 8767a507468a1d42b7c7fd3446fc509d6f913c05
Showing with 12 additions and 4 deletions.
  1. +12 −4 app/app.tsx
@@ -1,17 +1,25 @@
import React, { useState, useCallback } from 'react';
import * as ReactDOM from 'react-dom';

import React, { useState, useCallback } from 'react'
import * as ReactDOM from 'react-dom'
import { useObservable } from "rxjs-hooks"
import { map } from "rxjs/operators"

function Application () {
const [cnt, setCnt] = useState(0)
const handleClick = useCallback(event => setCnt(cnt + 1))

const cnt10 = useObservable(
cnt$ => cnt$.pipe(map(v => v * 10)),
[0],
[cnt]
)

return (
<div>
<div>
<button onClick={handleClick}>click</button>
</div>
count: {cnt}
<p>count: {cnt}</p>
<p>count * 10: {cnt10}</p>
</div>
)
}

0 comments on commit 8767a50

Please sign in to comment.
You can’t perform that action at this time.