usedatastore
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    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

    Keywords

    none

    Install

    npm i usedatastore

    DownloadsWeekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    7.77 kB

    Total Files

    9

    Last publish

    Collaborators

    • alexmerced