TypeScript Support
Hana Store is written in TypeScript and provides full support for TypeScript users. Every function and hook is fully typed and will provide type hints in your IDE.
useStore()/useStaticStore()/getStore()
These functions allow you to add types to shape your state using the same method as React's useState() hook.
import { useStore, useStaticStore, getStore } from '@hanabira/store';
const Component = () => {
const myItem = getStore<string>('item');
const [item, setItem] = useStore<string>('item');
const [state, setState] = useStaticStore<{ item: string }>();
return (
<div>
<p>{item}</p>
<button onClick={() => setItem('New value')}>Set item</button>
</div>
);
};
useReducer()/useStaticReducer()
import { useReducer, useStaticReducer } from '@hanabira/store';
const Component = () => {
const addSomething = useReducer<number>('add');
const addSomethingStatic = useStaticReducer<string>('add');
addSomething(1);
addSomethingStatic('1');
addSomething('1'); // Error
addSomethingStatic(1); // Error
...
};
