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

@cnstra/react

v1.0.1

Published

React bindings for CNS neural network-inspired event flow system

Downloads

10

Readme

@cnstra/react

React bindings for CNS neural network-inspired event flow system.

Installation

npm install @cnstra/react @cnstra/core

Usage

Basic Setup

import React from 'react';
import { CNSProvider, useCNS } from '@cnstra/react';
import { CNS, neuron, collateral } from '@cnstra/core';

// Create your CNS instance
const cns = new CNS([
  neuron('counter', {
    increment: collateral('increment'),
    decrement: collateral('decrement')
  }).dendrite({
    collateral: collateral('increment'),
    response: (payload, axon) => {
      // Handle increment logic here
      return axon.increment.createSignal();
    }
  }).dendrite({
    collateral: collateral('decrement'),
    response: (payload, axon) => {
      // Handle decrement logic here
      return axon.decrement.createSignal();
    }
  })
]);

function App() {
  return (
    <CNSProvider cns={cns}>
      <Counter />
    </CNSProvider>
  );
}

Using the Hook

import { useCNS } from '@cnstra/react';
import { collateral } from '@cnstra/core';

function Counter() {
  const cns = useCNS();
  
  const handleIncrement = () => {
    cns.stimulate(collateral('increment').createSignal());
  };
  
  const handleDecrement = () => {
    cns.stimulate(collateral('decrement').createSignal());
  };
  
  return (
    <div>
      <button onClick={handleIncrement}>+</button>
      <button onClick={handleDecrement}>-</button>
    </div>
  );
}

Multiple CNS Instances

You can create multiple CNS instances and use them in different parts of your app:

import React from 'react';
import { CNSProvider, useCNS } from '@cnstra/react';

// First CNS instance
const cns1 = new CNS([/* neurons */]);
const cns2 = new CNS([/* other neurons */]);

function App() {
  return (
    <div>
      <CNSProvider cns={cns1}>
        <Component1 />
      </CNSProvider>
      
      <CNSProvider cns={cns2}>
        <Component2 />
      </CNSProvider>
    </div>
  );
}

function Component1() {
  const cns = useCNS(); // Uses cns1
  // ...
}

function Component2() {
  const cns = useCNS(); // Uses cns2
  // ...
}

API

CNSProvider

A React context provider that makes a CNS instance available to child components.

Props:

  • cns: The CNS instance to provide
  • children: React components that will have access to the CNS context

useCNS()

A React hook that returns the CNS instance from the nearest CNSProvider.

Returns: The CNS instance

Throws: An error if used outside of a CNSProvider

TypeScript Support

The package is fully typed and supports generic types for your CNS instances:

import { CNSProvider, useCNS } from '@cnstra/react';

// With custom types
const cns = new CNS<MyCollateralId, MyNeuronId, MyNeuron, MyDendrite>([/* neurons */]);

function MyComponent() {
  const cns = useCNS<MyCollateralId, MyNeuronId, MyNeuron, MyDendrite>();
  // cns is fully typed
}