Skip to content

Releases: longsien/react-store

v1.1.0

16 Jun 06:14

Choose a tag to compare

Updated syntax

Local and session storage

Old syntax will continue to be supported until next major release.

// Old
const themeStore = storeLocal('theme', 'dark')
const tempStore = storeSession('temp', {data: []})

// New
const themeStore = store('dark').local('theme')
const tempStore = store({data: []}).session('temp')

Non-hook getters and setters

// Old
const theme = getStore(themeStore)
setStore(themeStore, 'dark')

// New
const theme = themeStore.get()
themeStore.set('dark')

Performance optimisations

Proxy caching

Proxies are now cached so paths pointing to the same objects or properties don't create new proxy objects.

const [name1, setName1] = useStore(userStore.name)
const [name2, setName2] = useStore(userStore.name)

// Old
console.log(name1 === name2) // false - new proxy was created

// New
console.log(name1 === name2) // true - points to the same proxy

Batched storage writes

Writes to both local and session storage are now batched into 16ms windows so firing multiple set operations at the same time will not block threads.

Function memoisation

Functions are now memoised and will not be recreated on each render.