Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
step-react-redux
Advanced tools
npm i step-react-redux
- OR - yarn add step-react-redux
initialState: object?
loading: JSX.Element?
import React from "react"
import ReactDOM from "react-dom"
import { Provider } from "step-react-redux"
import App from "./App"
const rootElement = document.getElementById("root")
const myInitialState = { /* your initial state */ }
/*
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={myInitialState}
loading={/* your loading UI*/}
>
<App />
</Provider>,
rootElement
)
WrappedComponent: Component
requiredKeys: string[]?
import React from "react"
import { connect } from "step-react-redux"
class UserPage extend React.Component {
// Your Component goes here
}
// this will connect all your store to UserPage component props
export default connect(UserPage)
/*
OR you can choose what keys this component using by providing requiredKeys argument
NOTE: Make sure that your requiredKeys values are already initiated.
*/
export default connect(UserPage, ["user", "someKey", "anotherKey"])
// You can also connect to deep state ( Up to 5 levels ) using dotted key.
export default connect(UserPage, ["user.name"])
// a prop with key "user_name" will be connected
// You can change deepKeyReplacer as a third optional argument
export default connect(UserPage, ["user.name"], "-")
// a prop with key "user-name" will be connected
state: object
import { xSetState } from "step-react-redux"
// Anywhere in your code
xSetState({ user: { id: 1, name: "Some Name" } })
// console logs => StepReactRedux.user, { id: 1, name: "Some Name" }
// Now all your connected components will have "user" prop
// Usage with API
async getMyData(){
xSetState({ isFetching: true })
try {
const response = await fetch("http://www.myServer.com/api/myData")
const responseJson = await response.json()
xSetState({ isFetching: false, myData: responseJson })
} catch (error) {
alert(error.message)
// Remeber that You can use xSetState ANYWHERE! as much as you want !
xSetState({ isFetching: false })
}
}
key: string
state: object
import { setStateForKey } from "step-react-redux"
// Similar to xSetState
// plus it can be used to set deep state up to 3 levels
setStateForKey("user", { id: 1, name: "Some Name" })
// 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!
key: string
import { getStateForKey } from "step-react-redux"
// Similar to setStateForKey
// but it can be used to get state and deep state
const userData = getStateForKey("user")
console.log(userData) // => { id: 1, name: "Some Name" }
const userName = getStateForKey("user.name")
console.log(userName) // => "Some Name"
// getting state for unknown key will return null
const someValue = getStateForKey("someKey")
console.log(someValue) // => null
const anotherValue = getStateForKey("anotherKey.subKey")
console.log(anotherValue) // => null
// Remeber that You can use getStateForKey ANYWHERE!
import React from "react"
import { useStateX } from "step-react-redux"
// Hooks Are used inside functional components
const MyComponent = (props) => {
// Depth: 2 levels
const isLoggedIn = useStateX("user.loggedIn")
// Depth: 3 levels
const userName = isLoggedIn ? useStateX("user.data.name") : "Guest"
// NOTE THAT DEPTH TREE SHOULD BE INITIALIZED BEFORE HOOKING IT
return (
<>
// Your Component goes here
<Text>Name: {userName}</Text>
</>
)
}
export default MyComponent
import React from "react"
import { xResetState } from "step-react-redux"
/*
Top level index in your code, call this method once during your develeopment process
to allow you to reinitialize your state again from Provider initialState prop
*/
// Call this Once, Then Don't forget to remove it.
xResetState()
FAQs
Implement React-Redux into your app in just One Step!
The npm package step-react-redux receives a total of 0 weekly downloads. As such, step-react-redux popularity was classified as not popular.
We found that step-react-redux demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.