I have a number of state variables (I am only showing 3):
class IntroductionPage extends React.Component<SomePageProps, {inId: string,
i1: string,
i2: string
}> {
constructor(props: any) {
super(props);
this.state = {inId:'',
i1:'',
i2:''
};
}
and I am reading key-value pairs from a DB:
+------------+------------+------------+
| start_type | field_name | start_text |
+------------+------------+------------+
| 0 | i1 | hi |
+------------+------------+------------+
| 0 | i2 | it's me! |
+------------+------------+------------+
| 0 | i3 | Schoon |
+------------+------------+------------+
for (var key in response.data) {
var dat = response.data[key];
getStartType=dat['start_type']//JSON.stringify(dat['start_type']);
for (var inner_key in dat) {
console.log('key=' + inner_key + ' value=' + dat[inner_key]);
}
gives
key=start_type value=0
key=field_name value=i1
key=start_text value=hi
...
Now is there any way I can loop through these retrieved value and set state, for example something like a loop or map version of this:
this.setState({dat['field_name']:dat['start_text']});
so the first row returned would be fieldname= i1, start_text ='hi' and so the loop would setState ({i1:'hi'})?