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

reto

v0.9.3

Published

React store with hooks.

Downloads

297

Readme

Reto

GitHub codecov npm version npm downloads npm bundle size (minified) Build Status codacy Vulnerabilities React

             ___                  __ 
            / _ \___    ___ _____/ /_
           / , _/ -_)  / _ `/ __/ __/
   ____   /_/|_|\__/   \_,_/\__/\__/ 
  / __/  / /____     _______         
 _\ \   / __/ _ \   / __/ -_)        
/___/   \__/\___/  /_/  \__/         
                                     

Flexible and efficient React Store with hooks.

Features

  • Supports all react hooks. Writing a store is just like writing a component.
  • Simple but efficient, quite easy to learn.
  • Use multiple stores to organize your data.
  • Dependency injection based on React Context.
  • Strongly typed with Typescript, also works well with JS.

Docs

English | 中文

Install

$ yarn add reto
# or
$ npm install reto --save

Try It Online

Edit react

A Simple Example

Every Store is a function similar to a custom hook. In the body of a Store function, you can use any react hooks, for example, useState, useEffect, useRef.

export function FooStore() {
  const [x, setX] = useState(initial)
  return {
    x,
    setX
  }
}

Then, you can provide a store "instance" using Provider component.

import {Provider} from 'reto'

<Provider of={FooStore}>
  <App/>
</Provider>

By using the useStore hook, you can retrieve the store "instance" in components, and subscribe to its changes.

import {useStore} from 'reto'

const App: FC = (props) => {
  const fooStore = useStore(FooStore)
  
  function changeStore() {
    fooStore.setX(fooStore.x + 1)
  }
  return (
    <div>
      <button onClick={changeStore}>Change</button>
      {fooStore.x}
    </div>
  )
}

So when you click the "Change" button, the setX function of fooStore is executed, thereby triggers the update of state x and the rerender of App component. Everything is simple and straightforward.