@lblanco/simple-store
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@lblanco/simple-store

minimal store for react projects using context.

NPM JavaScript Style Guide

Install

npm install --save @lblanco/simple-store

Example

https://lucasblanco.github.io/simple-store/

Usage

import React from 'react'

import SimpleStoreProvider from '@lblanco/simple-store'

interface Store {
  name: string
}

const App = () => {
  const initialStore = {
    name: 'Lucas'
  }

  return (
    <SimpleStoreProvider initialValue={initialStore}>
      <Child />
    </SimpleStoreProvider>
  )
}
import React from 'react'

import { useSimpleStore } from '@lblanco/simple-store'

const Child = () => {
  const [store, updateStore] = useSimpleStore<Store>()

  const updateName = (name) => {
    updateStore((state) => {
      state.name = name
    })
  }

  return (
    <input
      type='text'
      value={store.name}
      onChange={(e) => updateName(e.target.value)}
    />
  )
}

License

MIT © LucasBlanco

Readme

Keywords

none

Package Sidebar

Install

npm i @lblanco/simple-store

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

11 kB

Total Files

9

Last publish

Collaborators

  • lblanco