npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

observable-hooks

v4.2.3

Published

React hooks for RxJS Observables. Simple, flexible, testable and performant.

Downloads

175,355

Readme

observable-hooks

npm-version npm bundle size Build Status Coverage Status

Commitizen friendly Conventional Commits JavaScript Style Guide code style: prettier

logo

React hooks for RxJS Observables. Simple, flexible, testable and performant.

  • Seamless integration of React and RxJS.
    • Props and states to Observables.
    • Observables to states and props events.
    • Conditional rendering with stream of React Components.
    • Render-as-You-Fetch with React Suspense.
    • No tap hack needed. With Epic-like signature Observable operation is pure and testable.
  • Full-powered RxJS. Do whatever you want with Observables. No limitation nor compromise.
  • Fully tested. We believe in stability first. This project will always maintain a 100% coverage.
  • Tiny and fast. A lot of efforts had been put into improving integration. This library should have zero visible impact on performance.
  • Compatible with RxJS 6 & 7.

Why?

React added hooks for reusing stateful logic.

Observable is a powerful way to encapsulate both sync and async logic.

Testing Observables is also way easier than testing other async implementations.

With observable-hooks we can create rich reusable Components with ease.

What It Is Not

This library is not for replacing state management tools like Redux but to reduce the need of dumping everything into global state.

Using this library does not mean you have to turn everything observable which is not encouraged. It plays well side by side with other hooks. Use it only on places where it's needed.

At First Glance

import * as React from "react";
import { useObservableState } from "observable-hooks";
import { timer } from "rxjs";
import { switchMap, mapTo, startWith } from "rxjs/operators";

const App = () => {
  const [isTyping, updateIsTyping] = useObservableState(
    transformTypingStatus,
    false
  );

  return (
    <div>
      <input type="text" onKeyDown={updateIsTyping} />
      <p>{isTyping ? "Good you are typing." : "Why stop typing?"}</p>
    </div>
  );
};

// Logic is pure and can be tested like Epic in redux-observable
function transformTypingStatus(event$) {
  return event$.pipe(
    switchMap(() => timer(1000).pipe(mapTo(false), startWith(true)))
  );
}

Installation

yarn

yarn add observable-hooks

npm

npm install --save observable-hooks

Usage

Read the docs at https://observable-hooks.js.org.

Here is how I designed the API. Might give you a perspective on when use what.

mindmap

Examples are in here. Play on CodeSandbox:

Note that there are also some useful utilities for common use cases to reduce garbage collection.