Simple Redux is a state management library for the layman. It is just a global store to get and update values.
- Dead simple — One hook for receiving values and updating them.
- Redux based — Opinionated version of Redux. Core Redux concepts still apply.
- Plug & Play — Copy and paste the code below and you are ready to go.
Getting Started
-
Install the npm package.
npm i simple-redux-js -
Load the provider in App.js.
const App =<SimpleProvider initialState= token: 'default_token' ><Child></SimpleProvider> -
Access and update global state in any other component.
const Child = {const simpleDispatch =return<div><span></span><button onClick= ></div>}
Documentation
- useSimpleSelector (propertyName) Selects the property by name from the store.
const token =
- getSimpleState (propertyName) Selects the property by name outside of a component.
const token =
- getSimpleStates () Selects all states of the store outside of a component.
const allStates =
- store Access the store outside of a component.
store
- useSimpleDispatch () Creates a dispatch method to update the store.
const simpleDispatch =
- simpleDispatch (propertyName, propertyValue) Updates the property by name with the specified value.
const setToken =
Full Example
// App.js const defaultToken = localStorage const App = <SimpleProvider initialState= token: defaultToken > <Child> </SimpleProvider>ReactDom // Child.js const Child = { const simpleDispatch = const token = const setToken = return <div> <span>token</span> <button onClick= > </div> }
Publish
npm login
git commit (clean repo)
npm version patch (or minor)
npm publish
git push
License
simple-redux-js
is released under the ISC License.