react typescript dynamically set key state code example
Example: react typescript dynamically set key state
// the snackBarState is a string which would represent the key name in the state object
// i think this is a better way as opposed to doing a {...this.state, ['key]: value}
// equivalent.
// Will test this later on which is better. But for now if anyone is looking for this
// here it is
public fallbackErrorMessage = (error: any, message: string, snackBarState: string) => {
let updatedState: any = {
loading: false,
snackBarState: true,
message: message
}
this.setState(updatedState);
if (error !== undefined) {
throw error;
}
}