Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

react-store-toolkit

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-store-toolkit

React Store Toolkit is a library heavily inspired by [Redux Toolkit](https://github.com/reduxjs/redux-toolkit) but for React `Context API` and `useReducer`.

npmnpm
Version
0.1.0
Version published
Weekly downloads
1
-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

React-Store-Toolkit

React Store Toolkit is a library heavily inspired by Redux Toolkit but for React Context API and useReducer.

API

createStore(initialState, reducer, middlewareFn?, middlewareProps?):

export declare function createStore<State, MiddlewareProps = undefined>(initialState: State, reducer: Reducer<State, AnyAction>, middlewareFn?: ((state: State, action: AnyAction, middlewareProps?: MiddlewareProps) => void)[], middlewareProps?: MiddlewareProps): {
    useState: () => State;
    useDispatch: () => React.Dispatch<AnyAction>;
    StateProvider: React.FunctionComponent<Partial<State>>;
};

returned objectdescription
StateProviderThe context provider (React Element) that provides the store to all its children
useStateHook that returns the value of the state stored in the Provider
useDispatch()Hook that returns a dispatch function

createSlice()

  • This is the same createSlice API in Redux Toolkit except that we are not using Immer and your state updates need to return the newly created state.

createReducer()

  • This is the same createReducer API in Redux Toolkit except that we are not using Immer and your state updates need to return the newly created state.

createAction()

Example

Examples are available in the Example directory

FAQs

Package last updated on 04 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts