leva icon indicating copy to clipboard operation
leva copied to clipboard

Feature request: Export store class so it can be used with Jotai

Open astahmer opened this issue 4 years ago • 1 comments

Hey, I was trying to auto-sync an atom (from jotai) with the results of useControls (so that I can access it anywhere) So I thought of using the jotai/zustand util atomWithStore and by passing a custom leva store to useControls The thing is, the only way to create a custom leva store right now is from the useCreateStore hook

Could you export the Store class or a new createStore function ? We would also need the getValuesForPaths utils exported to get the same output as useControls

Then we would be able to do something like

const stateAtom = atomWithStore(new Store().useStore);
const useControlsResult = () => {
    const state = useAtomValue(stateAtom).data;
    return getValuesForPaths(state, Object.keys(state));
};

This would maybe also make persistence (#133) possible using atomWithStorage ?

astahmer avatar Oct 13 '21 21:10 astahmer