The state class takes in a StateSchema defined as whatever you want it to be. It allows for access anywhere from the program.
The StateSchema that the class will follow
interface StateSchema { myString: string | null; favoriteNumber: number; } const defaultState: StateSchema = { myString: null, favoriteNumber: 3, }; export const state: State<StateSchema> = new State(defaultState); Copy
interface StateSchema { myString: string | null; favoriteNumber: number; } const defaultState: StateSchema = { myString: null, favoriteNumber: 3, }; export const state: State<StateSchema> = new State(defaultState);
console.log(state.values.favoriteNumber); // 3 Copy
console.log(state.values.favoriteNumber); // 3
Set the values in state to be accessed anywhere
The partial values of StateSchema to change
const favoriteNumber: number = 5;state.setValues({ favoriteNumber }); Copy
const favoriteNumber: number = 5;state.setValues({ favoriteNumber });
The state class takes in a StateSchema defined as whatever you want it to be. It allows for access anywhere from the program.