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

recoil-spring

v0.1.7

Published

Jumpstart Recoil - less boilerplate, more fun.

Downloads

7

Readme

Recoil:Spring

recoil-spring CI

Recoil:Spring Logo Recoil:Spring Logo

Intro

Think React Toolkit or MobX State Tree but for Recoil. Opinionated but not too much :)

no dependencies (beyond peers: React & Recoil)

Tiny !

Documentation

See docs site -

Quick Start

The best place to find details of the Recoil:Spring API is at the doc site mentioned above. However, this section highlights the main concepts and usage.

Spring

Two ways to initialize: Object-map or chained calls.

Both code examples below are identical in their outcome:

Atom Family

One of Recoil's more useful yet cumbersome entities is the Atom Family. It's extremely useful for storing data over a collection. Yet, Recoil doesn't provide a way to track the items within the collection. Their docs explain that a custom atom should be employed to do that. Spring does this seamlessly when encountering a Family record.

Selectors

Simple Selector

Below is an example of the simplest read/write selector hook

import { createSelectorHook } from "recoil-spring";
import atoms from "../store";

const {
	borderColor
} = atoms;

const useCollageBorderColor = createSelectorHook(borderColor);

//recoil:spring will generate a selector key using the atom's key. 
//If you'd like to set your own key do the following:
const useCollageBorderColor = createSelectorHook("MyCustomBorderColorSelector", borderColor);

export default useCollageBorderColor;
import useCollageBorderColor from "./store/selectors/useCollageBorderColor";

const MyComponent = () => {
  const [borderColor, setBorderColor] = useCollageBorderColor();
		
  return (
		<input 
          type="number"
          value={borderColor}
          onChange={(e) => setBorderColor(parseInt(e.target.value))}
        />
  );
};

Computed

Below is an example of a computed selector, combining two atoms into one result:

import { createSelectorHook } from "recoil-spring";
import atoms from "../store";

const {
	borderWidth,
	borderColor,
} = atoms;

const useCollageBorder = createSelectorHook(
	//need to provide a key for the selector since we use a custom getter
	"CollageBorderSelector",
	(get) => [get(borderColor), get(borderWidth)],
);

export default useCollageBorder;

Using the resulting readonly selector hook is done in the following way:

import useCollageBorder from "./store/selectors/useCollageBorder";

const MyComponent = () => {
	const [color, width] = useCollageBorder();

	return (
		<div
			style={{ borderColor: color, borderWidth: `${width}px` }}>
			//...
		</div>
    );
};

Custom Setter

Below is a selector hook that reads one (atom) value but writes to two atoms. Using it works exactly the same as any other read/write hook

import { createSelectorHook } from "recoil-spring";
import atoms from "../store";

const {
	width,
	height,
} = atoms;

const useDimensions = createSelectorHook(
	width,
	(newVal, { set }) => {
		set(width, newVal);
		set(height, newVal);
	},
);

export default useDimensions;

Acknowledgements

logo's spring thanks to: Spring icons created by Zaenul Yahya - Flaticon