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

francis.react

v0.1.0

Published

React integration for Francis

Downloads

11

Readme

francis.react

The official type-safe React bindings for Francis.

Build status npm Bundle size (minified + gzip)

Installation

# npm
npm i --save francis.react francis react@next

# yarn
yarn add francis.react francis react@next

NOTE: francis.react requires francis >= 2.0.0 and react >= 16.8.0-alpha.1 as a peer dependency so installing these packages is required to use francis.react package.

If you're using TypeScript, you also need to install @types/react

# npm
npm i --save @types/react

# yarn
yarn add @types/react

Usage

Compatibility with React

francis.react package has exactly same API and it uses the same internals as normal React package. Because of this, all existing components using react imports are compatible with francis.react, so the usage is as simple as the following snippet:

-import React from "react"
+import React from "francis.react"

// ... rest of the app remains same ...

Embedding observables

Observables can be embedded to the virtual DOM like any other value. When observable emits a new value, the new value will trigger re-render of only the virtual DOM node it belongs to. And if you're using TypeScript, all of this is checked by the TS compiler:

Type checks pass

Type checks don't pass

Custom hooks

useStateAtom<T>(initialValue: T): Atom<T>

This hook works like useState but instead of [value, setter] tuple, the returned value is an Atom that preserves its state over re-renders:

interface CounterProps {
  state?: F.Atom<number>;
}

const Counter = ({ state = useStateAtom(0) }: CounterProps) => {
  return (
    <div>
      <p>Counter is: {state}</p>
      <div>
        <button onClick={() => F.modify(state, s => s + 1)}>++</button>
        <button onClick={() => F.modify(state, s => s - 1)}>--</button>
      </div>
    </div>
  );
};

useSubscription<T>(f: (e: AnyEvent<T> ) => void, obs: Observable<T>): void

Subscribes handler function f to the given observable once and disposes the subscription when the component unmounts. This function is curried so it can be piped like normal Francis operators:

const Component = () => {
  F.pipe(
    F.interval(1000, 1),
    F.scan(0, (acc, s) => acc + s),
    useSubscription(e => {
      F.isNext(e) && console.log("Seconds since mount:", e.value);
    })
  );
  return <div>Tsers</div>;
};

React Suspense compatibility

francis.react is compatible with React Suspense. If any of the embedded observables do not resolve (emit their first value) synchronously, the whole sub-tree gets suspended. Handling suspension is done like in normal React apps:

interface ResultsProps {
  value: F.Observable<string>;
}

const Results = ({ value }: ResultsProps) => {
  return <div>Result is "{value}"</div>;
};

const Main = () => {
  const result = F.later(1000, "Tsers!");
  return (
    <React.Suspense fallback={<div>Loading...</div>}>
      <Results value={result} />
    </React.Suspense>
  );
};

Server-side rendering

SSR is not supported at the moment. Support may come in future.

License

MIT