1.0.3 • Published 3 years ago

@lblanco/simple-store v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@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

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago