1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

continue typescript & chakra v1 migrations [skip ci]

This commit is contained in:
checktheroads
2020-12-17 16:37:36 -07:00
parent 0bb19082a0
commit 1fb1dfe182
34 changed files with 363 additions and 361 deletions

View File

@@ -1,5 +1,5 @@
import { createState, useState } from '@hookstate/core';
import type { TGlobalState } from './types';
import type { TGlobalState, TUseGlobalState } from './types';
// const StateContext = createContext(null);
@@ -26,8 +26,23 @@ import type { TGlobalState } from './types';
// export const useHyperglassState = () => useContext(StateContext);
export const globalState = createState<TGlobalState>({
const defaultFormData = {
query_location: [],
query_target: '',
query_type: '',
query_vrf: '',
} as TGlobalState['formData'];
const globalState = createState<TGlobalState>({
isSubmitting: false,
formData: { query_location: [], query_target: '', query_type: '', query_vrf: '' },
formData: defaultFormData,
});
export const useGlobalState = () => useState(globalState);
export function useGlobalState(): TUseGlobalState {
const state = useState<TGlobalState>(globalState);
function resetForm(): void {
state.formData.set(defaultFormData);
state.isSubmitting.set(false);
}
return { resetForm, ...state };
}

View File

@@ -1,3 +1,4 @@
import type { State } from '@hookstate/core';
import type { IConfig, TFormData } from '~/types';
export interface THyperglassProvider {
@@ -9,3 +10,9 @@ export interface TGlobalState {
isSubmitting: boolean;
formData: TFormData;
}
interface TGlobalStateFunctions {
resetForm(): void;
}
export type TUseGlobalState = State<TGlobalState> & TGlobalStateFunctions;