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-hsc

v1.0.0

Published

React Hook Store Context

Downloads

8

Readme

React-HSC

Made with create-react-library

NPM JavaScript Style Guide

React Hook Store Context

It is a Simple Hook Store Context for react project using hooks. Global State Management.

CodeSandbox Basic Example

Edit codesandbox

Install

React HSC is available as a package on NPM for use with a module in your React application:

# NPM
npm install react-hsc

# Yarn
yarn add react-hsc

Purpose

The Redux HSC package is intended to be a simple alternative to REDUX for handling APPLICATION STATUS. It was originally created to understand the handling of REACT's useContext.

  1. StoreContext is a default component context.

  2. createStore functionality handles declared reducers, similar to REDUX's combineReducers.

  3. useSelector functionality manages access to the ROOT-STATE similar to REDUX's useSelector.

  4. useDispatch functionality triggers an action that will be sent to the declared REDUCERS, this method supports parameters like STRING, ACTION, FUNCTION, ASYNC FUNCTION.


NOTE

Additionally, the connection functionality to the REDUX-DEV-TOOLS plugin was included to see the change of state managed by the library.


Usage

import React from 'react'
import ReactDOM from 'react-dom'
import StoreContext, { createStore, useSelector, useDispatch } from 'react-hsc'

// 1.- Reducer Function
export const counterReducer = (state, action) => {
    switch (action.type) {
        case '++':
            return { counter: state.counter + 1 };
        case '--':
            return { counter: state.counter - 1 };
        default:
            return state;
    }
}

// 2.- HSC Store
export const basicStore = createStore({
    C1: [counterReducer, { counter: 0 }],
});

// 3.- Basic App with StoreContext
export const BasicApp = () => {
    return (
        <StoreContext.Provider value={basicStore}>
            <CounterDisplay />
            <CounterButtons />
        </StoreContext.Provider>
    )
}

// 4.- useSelector Example
export const CounterDisplay = () => {
    let { counter } = useSelector(state => state.C1);
    return (
        <h3>Counter: {counter}</h3>
    )
}

// 5.- useDispatch Example
export const CounterButtons = () => {
    const dispatch = useDispatch();
    const onClick = (type) => {
        dispatch({ type })
    }
    return (
        <div>
            <button onClick={e => onClick("++")}>+1</button>
            <button onClick={e => onClick("--")}>-1</button>
        </div>
    )
}

// 6.- Run Example
ReactDOM.render(<BasicApp />, document.getElementById('root'))

Documentation

The React-HSC docs are available at https://yracnet.github.io/react-hsc/manual.html.

Example

The React-HSC docs are available at https://yracnet.github.io/react-hsc/index.html.

License

MIT © Willyams Yujra