usedatastore
v1.0.1
Published
State Management Components and Hooks
Downloads
2
Readme
usedatastore
State Management Components and Hooks
Install
npm install --save usedatastore
Usage
Step 1 - Initialize
Create a DS.js in your src folder and do the following
const createDataStore = require('usedatastore')
// Define and initialState and Reducer
export const [DataStore, useDataStore] = createDataStore(initialState, reducer)
Wrap Your App Components with DataStore
// App.jsx
import React, { Component } from 'react'
import {DataStore} from "./DS.js
const App = (props) => {
return <DataStore><OtherComponent/></DataStore>
}
Pull data using hook in any component
// /components/component.jsx
import React from "react'
import {useDataStore} from "../DS.js"
const Component = (props) => {
const {dataStore, dispatch} = useDataStore()
return <><h1>{dataStore.title}</h1>
<button onClick={() => dispatch({type:"something", payload: 5})}>Click Me</button>
}
License
MIT © AlexMercedCoder