BREAKING CHANGE
React Native Redux instead.
Now react-native users should useStep React Redux
Implement React-Redux into your react web app in just One Step!
- No Store configuration needed!
- No MiddleWares needed, no more dispatch complications.
- No Reducers or ACTIONS required.
- No Persistance configuration needed, All data are persisted!
- Very simple way to change store state, just like Component setState !
- Simply connect your components with simpler connect function
- Easily use hooks for your functional component, Dive deep in state up to 5 levels.
- Built on redux, react-redux and redux-persist, No previous experience needed.
Instalation
npm i step-react-redux
- OR - yarn add step-react-redux
Then.. Your Are Done !
Usage
Provider
Props
initialState: object?loading: JSX.Element?
Usage
/* Important Note: state will initialize for first time only, then you have to use xSetState or setStateForKey to change it, If you want to reinitialize state, you have to call xResetState once. See xResetState below*/ ReactDOM.render Provider initialState= loading= App / /Provider, rootElement
connect
Arguments
WrappedComponent: ComponentrequiredKeys: string?
Usage
// this will connect all your store to UserPage component props /* OR you can choose what keys this component using by providing requiredKeys argument NOTE: Make sure that your requiredKeys values are already initiated.*/ // You can also connect to deep state ( Up to 5 levels ) using dotted key. // a prop with key "user_name" will be connected // You can change deepKeyReplacer as a third optional argument// a prop with key "user-name" will be connected
xSetState
Arguments
state: object
Usage
// Anywhere in your code xSetState// console logs => StepReactRedux.user, { id: 1, name: "Some Name" }// Now all your connected components will have "user" prop // Usage with API async getMyData
setStateForKey
Arguments
key: stringstate: object
Usage
// Similar to xSetState// plus it can be used to set deep state up to 3 levels setStateForKey"user", // console logs => StepReactRedux.user, { id: 1, name: "Some Name" }// Now all your connected components will have "user" prop // Usage to set deep state setStateForKey"user.name", "New Name" // console logs => StepReactRedux.user.name, "New Name" // Remeber that You can use setStateForKey ANYWHERE!
getStateForKey
Arguments
key: string
Usage
// Similar to setStateForKey// but it can be used to get state and deep state console.loguserData // => { id: 1, name: "Some Name" } console.loguserName // => "Some Name" // getting state for unknown key will return nullconsole.logsomeValue // => null console.loganotherValue // => null // Remeber that You can use getStateForKey ANYWHERE!
useStateX (Hook)
React Stateful Function.
You may like to try our new set of hooksUsage
// Hooks Are used inside functional components
xResetState (Dev Only)
Usage
/*Top level index in your code, call this method once during your develeopment processto allow you to reinitialize your state again from Provider initialState prop*/ // Call this Once, Then Don't forget to remove it. xResetState