const updatedState = {}; if (vars.length) { vars.forEach(v => { updatedState[v] = ''; this.setState({ ...this.state ...updatedState, }); }); }