# store

## How to use

```jsx
import { Plugin } from '@root'

Plugin.store({
    ...STORE_PAYLOAD
})
```

## Store payload

| Param        | Typeof   | Default | Required | Description                                                         |
| ------------ | -------- | ------- | :------: | ------------------------------------------------------------------- |
| **key**      | String   | null    |     ✅    | the cache key to be used to save/get/remove your data from store.   |
| **data**     | Any      | null    |     ✅    | the data item to be stored.                                         |
| **callback** | Function | null    |     ❌    | a callback will be called when the data is saved/removed from store |
| **method**   | String   | GET     |     ❌    | a method to save/get/remove available methods: `GET, POST, DELETE`  |
| **personal** | Boolean  | false   |     ❌    | if true Dashboard will append the user sub to the key automatically |

## Save data to store

```jsx
import { Plugin } from '@root'

const item = {
    id: 'item-id',
    name: 'item name'
}

const onSave = () => {

}

Plugin.store({
    key: 'my-store-key',
    data: item,
    method: 'POST',
    callback: onSave
})
```

####

## Get data from store

```jsx
import { Plugin } from '@root'

const onGet = storedData => {
    console.log(storedData)
    /*
        Output:
        {
            id: 'item-id',
            name: 'item name'
        }
    */
}

Plugin.store({
    key: 'my-store-key',
    method: 'GET', // can be ignored, as GET is the default method for cache
    callback: onGet
})
```

## Remove data from store

```jsx
import { Plugin } from '@root'

Plugin.store({
    key: 'my-store-key',
    method: 'DELETE'
})
```
