@youri-kane/react-context-store
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

React Context Store

This package allows to create a types React.Context for typescript user.

Example

    import { createContextStore } from '@youri-kane/react-context-store';

    const initState = {
        blabal: true,
    };
    const context = createContextStore<
        typeof initState, 
        | { type: "actionA"; payload: boolean }
        | { type: "actionB"; payload: undefined }
    >({
        initState: {
            blabal: true,
        },
        reducer: (state, action) => {
            switch (action.type) {
            case "actionA":
                return {
                ...state,
                blabal: action.payload,
                };
            case "actionB":
                return {
                ...state,
                blabal: false,
                };
            default:
                return state;
            }
        },
        namespace: "Test Store",
    });

    export const useTextContext = context.useStoreContext
    export const TestContextProvider = context.StoreProvider
    export const TestStoreConsumer = context.StoreConsumer

Readme

Keywords

none

Package Sidebar

Install

npm i @youri-kane/react-context-store

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

14 kB

Total Files

9

Last publish

Collaborators

  • youri-kane