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

react-redux-peach

v1.0.1

Published

Make and develop web apps easier with react hooks and redux

Downloads

7

Readme

react-redux-peach

Make and develop web apps easier with react hooks and redux

Hooks make react apps more scalable and more effective

Installation

$ npm install --save react-redux-peach

# So you need react, react-dom and redux
$ npm install --save react@next react-dom@next redux
# Add @next to install latest react version that support hooks.

Redux-peach

More ability of this package is because of redux-peach

redux-peach make actions and dispatch them in simple shape and it's completely favorable with react hooks.

Usage

Store

Create your own redux store like before, but please don't forget these two points:

  • redux-thunk middleware, append it to middlewares.
  • use rootReducer as first parameter of createStore

Another simple way to start, is that make store with Store type redux-peach, you can initialize and configure your store with 3 lines:

// -- src/store.js --
import {Store} from 'react-redux-peach'
const store = new Store()
store.configure()
export default store // we need to export store to use in context provider.

Provider

As you know we need to create a context and pass store through it, here is Provider code:

import { Provider } from 'react-redux-peach'
import store from 'src/store'
<Provider value={store}>...</Provider>

Actions

For example we want to make a simple counter so we need action to dispatch INCREMENT action and then reducers increase counter value.

To find out how to define simple and powerful actions please see redux-peach define actions

import { Action } from 'react-redux-peach'
Action('INCREMENT')
  .setScope('math.numbers')
  .setOnSucceedListener(action => ({ counter: action.payload }))
  .setInitialState({ counter: 0 })

Hooks

in this example our hook name should be useIncrement that will return counter and function that will increase counter. So we will have this:

function componentName () {
  const [counter, increment] = useIncrement()
  return <some-jsx></some-jsx>
}

Actually in simple examples of hooks we need to write useState and call the setter function and that's it, but when we want to work with redux, it would be a little different, first we need to dispatch an action and then we should call setter function.

what should be in useIncrement?

I have really really tried to make this codes simple and realizable, I hope that's okay.

useIncrement should be like this:

import {useDispatch, useStateMapper} from 'react-redux-peach'
function useIncrement() {
  // incrementAction: you have defined it before.
  const increment = useDispatch(incrementAction)
  let counter
  counter = useStateMapper(incrementAction, 'counter')
  // OR
  counter = useStateMapper('math.numbers.counter')
  // OR
  counter = useStateMapper(state => state.math.numbers.counter)
  return [counter, useCallback(() => increment(counter + 1), [counter])]
}
  • useDispatch return a dispatcher that just need to pass it payload.
  • useStateMapper we need to map our scope variable with state. as you seen we can use useStateMapper in three different shapes.

So with const [counter, increment] = useIncrement() we are done. Call increment will dispatch an action and after update value in store, counter will be update.

Other useful hooks:

useFindAction:

After running useDispatch action automatically hook to store and you can access action with this function just with actionName.

useInitialState:

when you call useDispatch, useInitialState will call in it and will set InitialState with use State types. useInitialState will run memoize function to prevent run on every render.

useAction:

After state Initialization, useAction will call, this method will hook action to store and make action. (run make method of action), Also this method should not run on every rendering, so return memoize function.

Contribute

Please feel free to contact with me and send your feedback about me and this package. if want to collaborate, it's my pleasure.

License

ISC