i want to know if i can set the same value for multiple keys in the following:
- React functional component state:
const [state, setState] = useState(
key1: 'same-value',
key2: 'same-value',
key3: 'same-value'
);
- React class component state:
state = {
key1: 'same-value',
key2: 'same-value',
key3: 'same-value'
};
- Javascript object:
const state = {
key1: 'same-value',
key2: 'same-value',
key3: 'same-value'
};
I want to know if something like this is possible:
const state = {
state1, state2, state3: 'same-value';
};
state.state1 = state.state2 = state.state3 = 'same-value';this is the only way that comes to my mind.JSON.parse('{' + '"state,'.repeat(30).split(',').map(function(v, i, a){return v ? v + ++i : null}).join('":"same-value",').slice(0, -1) + '}'):-D