Save the state which created by Storken to a storage.
Supports all storages that implements Storage Interface.
import { create as createStore } from 'storken'
import StorkenStorage from 'storken-storage'
const [useStorken] = createStore({
plugins: {
storage: StorkenStorage
},
storkenOptions: {
user: {
storage: window.localStorage
}
}
})
A Storken that contains storage
key in its options will be saved to the specified storage when it is setted in order that the state value can be set from the storage automatically or manually.
Let's another example that uses AsyncStorage in React Native.
import { create as createStore } from 'storken'
import StorkenStorage from 'storken-storage'
import AsyncStorage from '@react-native-community/async-storage'
const [useStorken] = createStore({
plugins: {
storage: StorkenStorage
},
storkenOptions: {
user: {
storage: AsyncStorage
}
}
})
Storage options should be passed in storkenOptions
by key.
disableStorageOnMount
:default: false
disables the automatic setting of state's value from storage when the component is mounted.disableSetterOnStorage
:default: true
disables automatically triggering the setter if exists, when setted the state.
Sets value from the storage to the state.
Saves current value of the state to the storage.
Removes value from the storage.
remove
argument runs remove()
function of StorkenObject. Which removes also the state from the whole store.
Removes values of multiple states from the storage.
The events that triggers respectively for every state except the last two.
This is triggered while loading value from the storage.
This is triggered when loaded the value from the storage.
This is triggered while setting from the storage.
This is triggered when value is setted from the storage.
This is triggered while current value saving to the storage.
This is triggered when current value is saved to the storage.
This is triggered while removing the value from the storage.
This is triggered when removed the value from the storage.
Distributed under the MIT License.
You can contribute by fork this repositry and make pull request.