react typescript dynamically set key state

Solutions on MaxInterview for react typescript dynamically set key state by the best coders in the world

showing results for - "react typescript dynamically set key state"
Cristina
19 Jan 2018
1// the snackBarState is a string which would represent the key name in the state object
2// i think this is a better way as opposed to doing a {...this.state, ['key]: value}
3// equivalent. 
4// Will test this later on which is better. But for now if anyone is looking for this 
5// here it is
6public fallbackErrorMessage = (error: any, message: string, snackBarState: string) => {
7
8        let updatedState: any = {
9            loading: false,
10            snackBarState: true,
11            message: message
12        }
13
14        this.setState(updatedState);
15
16        if (error !== undefined) {
17            throw error;
18        }
19    }
similar questions
queries leading to this page
react typescript dynamically set key state