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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-subx

v0.9.0

Published

Official React bindings for SubX

Downloads

92

Readme

react-subx

Build Status npm version

Official React bindings for SubX.

Installation

yarn add react-subx

Usage

import SubX from 'subx'
import { Component } from 'react-subx'
import React from 'react'
import ReactDOM from 'react-dom'

const store = SubX.create({
  number: 0,
  decrease () {
    this.number -= 1
  },
  increase () {
    this.number += 1
  }
})

class App extends Component {
  render () {
    const store = this.props.store
    return <div>
      <button onClick={e => store.decrease()}>-</button>
      <span>{store.number}</span>
      <button onClick={e => store.increase()}>+</button>
    </div>
  }
}

ReactDOM.render(<App store={store} />, document.getElementById('container'));

It is super simple to use. Just let our components extend Component from 'react-subx' instead of React.Component. Make our store a SubX object, and update our store in whatever way we want. react-subx takes care of everything else.

TodoMVC

Here is a standard TodoMVC implemented with React & SubX

online demo

Philosophy

A good state container should meet the following 3 criteria:

  1. Minimize computation
  2. Minimize rendering (of frontend framework, such as React)
  3. Minimize the burden of developers

Minimize computation

Use as many computed properties as necessary. SubX is smart enough to cache computed properties to avoid computation.

Minimize rendering

When working with a frontend framework such as React, it is important to control the number of re-render. Lots of re-render often leads to performance issues.

react-subx takes care of this for us automatically. We don't need to define shouldComponentUpdate. We don't need to turn to reselect either. And it just works and it is just performant.

Minimize the burden of developers

I used to be a Ruby developer. I cannot agree more on "make developers happy".

With react-subx, developers do NOT have to learn actions, reducers, dispatchers, selectors...etc.

Just follow common sense and it just works and it's just performant.

How does react-subx work?

Simply put, react-subx deems React's render method as a computed property.

It applies the same algorithm which powers SubX computed properties to React's render method. So that render method won't be invoked until absolutely necessary.

Pitfalls

react-subx tracks changes to React components' props, it is smart enough to figure out when to re-render the component.

So if we want a piece of data to be tracked, make it a SubX object(or part of a SubX object) and pass it to React component via props.

Never access global state directly

It is bad practice for a React component to access global state directly. It should only receive data via props. If a React component accesses global data directly, react-subx won't re-render that component for us.

Don't "cache" data out of render method in React component

This one is hard to comprehend. Let me provide an example:

import SubX from 'subx'
import { Component } from 'react-subx'
import React from 'react'
import ReactDOM from 'react-dom'

const store = SubX.create({
    todos: []
})

class App extends Component {
    constructor(props) {
        super(props)
        this.todos = props.store.todos
    }
    render() {
        return this.todos.map(todo => todo.tite).join(', ')
    }
}

ReactDOM.render(<App store={store} />, document.getElementById('container'));

In the sample above, we "cached" this.todos in constructor. It might be a bad idea.

Let's say we execute store.todos = [...] somewhere else. Then store.todos is no longer the this.todos we cached. Later changes to store.todos won't re-render component at all because it uses a cached version of this.todos which has been disconnected from store.

If we want to save a todos for later reference, we can do it right inside the render method:

render() {
    const todos = this.props.store.todos
    return todos.map(todo => todo.tite).join(', ')
}

Todo

Support React Hooks