Coder Social home page Coder Social logo

Comments (7)

voliva avatar voliva commented on June 1, 2024 1

You can also do bind(someObservable$.pipe(startWith("")))

from react-rxjs.

jyssh avatar jyssh commented on June 1, 2024 1

That works! Thank you for this library and your prompt response.

from react-rxjs.

voliva avatar voliva commented on June 1, 2024

That same paragraph starts with a key point:

If you don't give it a default value, you will need to make sure that observable has a subscription active before the Component that uses that hook is called.

The behaviour that <Subscribe> has regarding auto-subscribing only applies for those states that don't have a default value.

In cases where the state does have a default value, the component doesn't require an active subscription to that state during rendering. Consequently, <Subscribe> will not subscribe to it.

If you do require an open subscription for that state, you can make use of the source$ parameter, as you've already noted.

from react-rxjs.

jyssh avatar jyssh commented on June 1, 2024

Ok. My use case is a multi-step (or multi-"page") form, throughout which I need to keep several state-streams - each associated with an input - alive.

However, the components subscribed to those state-streams would come and go as the form changes its step/page. But I would like to those state-streams retain their values and not reset to 0 (when the subscriptions to them reach 0).

I see <Subscribe> as a way to keep subscriptions to those streams alive while the page under the <Subscribe> keep switching.

Is this way of using <Subscribe> correct?

If not, then is there another way to achieve my purpose?

from react-rxjs.

jyssh avatar jyssh commented on June 1, 2024

If you do require an open subscription for that state, you can make use of the source$ parameter, as you've already noted.

If <Subscribe source$> is the only way, then in order to keep more than 1 state-streams alive, I imagine I would have to merge those streams into one, and use that merged stream as the source$. Correct?

from react-rxjs.

voliva avatar voliva commented on June 1, 2024

If <Subscribe source$> is the only way, then in order to keep more than 1 state-streams alive, I imagine I would have to merge those streams into one, and use that merged stream as the source$. Correct?

Yes, exactly. The auto-subscribing feature of Subscribe was added in the 0.8.0 release. Before that, you would have to merge all of your streams and pass them manually to the source$.

After 0.8.0 source$ became optional, and it works great for the vast majority of cases. However, there are still some cases where you still need to manage your subscriptions manually... Either because you want to activate them regardless if a component is mounted or not, or to avoid the double-render that Subscribe does when mounting for the first time (and maybe other cases I haven't found yet).

from react-rxjs.

jyssh avatar jyssh commented on June 1, 2024

from react-rxjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.