Answers for "react typescript dynamically set key state"

0

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;
        }
    }
Posted by: Guest on January-26-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language