Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

evilfactorylabs/useGlobalState

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@evilfactory/global-state

⚛️ Simple State Management from react to react powered by React Hook.

Install

$ yarn add -E @evilfactory/global-state
$ npm i @evilfactory/global-state 

Usage

Features

  • Zero configuration ✅.
  • React hooks based API ✅.
  • React Native supported ✅.
  • Global State & shareable ✅.
  • Redux Dev Tools supported 🙏.

API

Table of Contents

StateProvider

as Wrapper of your React Application.

Parameters

  • props Object
    • props.reducer
    • props.initialState
    • props.children

Properties

Examples

Example Use of <StateProvider/>.

import React from 'react' import App from './you-app.js' import {StateProvider} from 'evilfactorylabs/global-state' const initialState = { todo: [] } function todoReducer(state, action) { switch (action.type) { case "ADD_TODO": return { ...state, todo: [...state.todo, action.todo] }; default: return state; } } ReactDOM.render( <StateProvider reducer={todoReducer} initialState={initialState}> <App/> </StateProvider> , document.getElementById('root'))

useGlobalState

Parameters

Examples

import {useGlobalState} from '@evilfactorylabs/global-state' ... const createTodo = (state, action, todo) => { return action({ type: 'ADD_TODO', data: todo, }) } const [,addTodo] = useGlobalState(createTodo) addTodo({title: 'New Task'}) ...

Packages

No packages published

Contributors 2

  •  
  •