1.0.1 • Published 4 years ago

usedatastore v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

usedatastore

State Management Components and Hooks

NPM JavaScript Style Guide

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