1.0.5 • Published 3 years ago

@youri-kane/react-context-store v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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