json / src /store /useJson.ts
xinnni's picture
Upload 146 files
f909d7c verified
raw
history blame
No virus
638 Bytes
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;