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

remini

v1.4.2

Published

Simple and powerful state management in React and Preact

Downloads

1,330

Readme

Remini

Simple and powerful state management in React and Preact

npm version npm bundle size code coverage typescript supported

Easy to learn

➪ Small and quick

➪ For any scale apps

Get started

At first you have a state 😊

const $user = box({ email: '[email protected]' })
const $enabled = box(true)
const $counter = box(42)
const $books = box([ 'The Little Prince', 'Alice in Wonderland' ])

At second bind state to React component!

const Books = () => {
  const books = useBox($books)
  return <ul>
    {books.map(book => <li>{book}</li>)}
  </ul>
}

At third update the state 👍

const BookForm = () => {
  const [name, setName] = React.useState('')
  return <p>
    <input 
      value={name}
      onChange={event => setName(event.target.value)} 
      />
    <button
      onClick={() => update($books, books => [...books, name])}
      >Add</button>
  </p>
}

Edit Simple and powerful state management with Remini

At fourth share your logic 😉

// ./books.shared.js
export const $books = box([])
export const $loading = box(false)

export const load = async () => {
  set($loading, true)

  const response = await fetch('https://example.com/api/books')
  const books = await response.json()

  set($books, books)
  set($loading, false)
}
const BooksLoad = () => {
  const loading = useBox($loading)
  return <p>
    {loading ? 'Loading...' : (
      <button onClick={load}>Load</button>
    )}
  </p>
}

Why Remini?

Your coding time saver!

Minimal, well structured, and flexible codebase save a lot of developer time for maintain and grouth your React applications.

How it works

Usually when you just start React project or have a very small one, your codebase is short, undestable and simple, you can easily google examples of common issues.

But as you write the business logic of your application, the code gets larger and it becomes more and more difficult to understand the abundance of files, tricks and code pieces.

You should clear understand where is a place to your logic, how you can write as many code as you want without reduce your application maintance.

  • How to make a simple React application who can easily upscale to large application by business demand
  • How to organize your code clean with minimal states and convinient separated logic
  • How to speed up your application and reduce boilerplate

My answer is Remini 😍

Multiple stores vs single store

One of the manifestations is the multiple-store architecture. The main reason is the independent modules decomposition. For flexible growth, you should separate your code. Your app should be built on top of separated modules composition. There is each module contains some data and logic.

It’s a very good architecture decision because you can develop and test each module separately. You can easily reuse modules between projects. And when you use a lazy load for some parts of your app, you will never have any problem with it, just import it and use it. It should be simple!

Ok. The first one is the separated module decomposition, and what's the next?

If each module has its own state and logic it is very convenient to use separate stores to control data flow.

At that moment the good time to make the postulate: each store should be simple, and never recommend to make deeply nested state. The better way is following to KISS principle.

Selection from store

One of the most frequently used functions during work with the state is the selection. Selection is the transformation of your state, fairly for performance reasons. You should update your view components only when updated the data used inside. This is the rendering optimization.

For example, your user state is big it has a lot of user settings and some stuff. If you have an avatar view component, it should be updated only when the avatar changes, not for each user state update.

import { box, get, wrap } from 'remini'

const $user = box({
  name: 'Joe',
  email: '[email protected]',
  settings: {},
  avatar: 'https://avatar.com/1.jpg'
})

const $avatar = wrap(() => get($user).avatar)
import { useBox } from 'remini/react'

const Avatar = () => {
  const avatar = useBox($avatar)
  return (
    <img src={avatar} />
  )
}

You can see how it’s easy to make that tiny, but very effective optimization!

You don't have to render everything. You should render only what you need! No more, no less)

Composition of stores

Step by step on the application growing upstairs you will have cases of the necessary combination of multiple stores to one. It should be simple)

import { box, get, wrap } from 'remini'

const $firstName = box('John')
const $lastName = box('Doe')

const $fullName = wrap(() => {
  return get($firstName) + ' ' + get($lastName)
})

Here we combine several stores into one for convenient use in some view components.

References

Install

npm install remini
# or
yarn add remini

Enjoy your code!