Using immutability-helper in React to set variable object key : <p>I have a function I want to write in React.  In my class I have a state object <code>fields</code> that looks like this:</p>

<pre><code>this.state = {
  step: 1,
  fields: {
    type: '',
    name: '',
    subtype: '',
    team: '',
    agreement: ''
  }
};
</code></pre>

<p>I have various functions that assign those keys using <code>immutability helper</code> that generally look like:</p>

<pre><code>assignType(attribute) {
  var temp = update(this.state.fields, {
    type: {$set: attribute}
  });

  this.setState({
    fields: temp
  });
}
</code></pre>

<p>What I would <em>like</em> to do is use a function that's more generic and do something like this:</p>

<pre><code>assignAttribute(field, attribute) {
  var temp = update(this.state.fields, {
    field: {$set: attribute}
  });

  this.setState({
    fields: temp
  });
}
</code></pre>

<p>But, this doesn't work.  What can I do to use a variable key using <code>immutability-helper</code>?</p>
