File size: 638 Bytes
f909d7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import { create } from "zustand";
import useGraph from "src/store/useGraph";
interface JsonActions {
setJson: (json: string) => void;
getJson: () => string;
clear: () => void;
}
const initialStates = {
json: "",
loading: true,
};
export type JsonStates = typeof initialStates;
const useJson = create<JsonStates & JsonActions>()((set, get) => ({
...initialStates,
getJson: () => get().json,
setJson: json => {
set({ json, loading: false });
useGraph.getState().setGraph(json);
},
clear: () => {
set({ json: "", loading: false });
useGraph.getState().clearGraph();
},
}));
export default useJson;
|