1.0.22 • Published 2 years ago

@jitcoder/usestore v1.0.22

Weekly downloads
20
License
ISC
Repository
github
Last release
2 years ago

useStore

useStore is a library that allows you to maintain the state of your application globally while being able to use certain parts of the state with hooks.

Parts of the state can be targeted with a path. eg. todo.items

Whenever that key is changed, the appropriate hooks will be called.

In the below example, if store.set('todo.items') is called, it will cause any component that used the useStore hook on key todo.items to be re-rendered.

Example Usage

api.js

import store from '@jitcoder/usestore';

export const getItems = async () => {
  const results = await axios.get('http://localhost:3001/todo');
  store.set('todo.items', results.data || []);
  return results.data;
}

MyComponent.jsx

import React from 'react';
import { useStore } from '@jitcoder/usestore'

const ItemView = () => {
  const [items] = useStore('todo.items', []);
  return (
    <List>
      {
        items.map((i) => {
          return (
            <ListItem>
              <ListItemText primary={i.title} />
              <ListItemIcon>
                <Button onClick={() => deleteItem(i.id)}>
                  <DeleteIcon />
                </Button>
              </ListItemIcon>
            </ListItem>
          )
        })
      }
    </List>
  );
}
1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago