Skip to content

How do you use useRef with this library? #116

Answered by crimx
tansanDOTeth asked this question in Q&A
Discussion options

You must be logged in to vote

If you need a click event stream, there is an example from the docs:

import { useObservableCallback, useSubscription } from 'observable-hooks'

const Comp = () => {
  const [onChange, textChange$] = useObservableCallback<
    string,
    React.FormEvent<HTMLInputElement>
  >(event$ => event$.pipe(
    pluck('currentTarget', 'value')
  )) // or just use "pluckCurrentTargetValue" helper

  useSubscription(textChange$, console.log)

  return <input type="text" onChange={onChange} />
}

If you need a dom stream:

import React, { useRef } from 'react';
import { switchMap, fromEvent, Observable } from 'rxjs';
import { useObservable, useSubscription } from 'observable-hooks'

export function App() {

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@crimx
Comment options

@tansanDOTeth
Comment options

Answer selected by crimx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants