Skip to content

Component not reloading #326

Closed Answered by voliva
SmoothieAq asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, there's a bit of misunderstanding on how this library should be used and react itself

bind returns two things: A hook to use the value in a React component, and a shared stream to keep composing with other streams. bind should never be called inside a react component. You call it outside just once, grab the hook and use it inside your component.

The convention in React is to name your hooks starting with use, so your example should become:

const emit$: Observable<number> = webSocket<Array<Array<never>>>("http://localhost:8000/emits/stream").pipe(
    mergeMap(l => l), map(e => e[2])
)
const [useEmission, emit$$] = bind(emit$)
emit$$.subscribe(e => {console.log("emit", e)})

const Emi…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by SmoothieAq
Comment options

You must be logged in to vote
0 replies
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
Converted from issue

This discussion was converted from issue #325 on March 10, 2025 22:17.