Skip to content

Instantly share code, notes, and snippets.

@howtomakeaturn
Created April 12, 2019 06:22
Show Gist options
  • Select an option

  • Save howtomakeaturn/f43c750bb5ddd0ca48a42f3f64f10d23 to your computer and use it in GitHub Desktop.

Select an option

Save howtomakeaturn/f43c750bb5ddd0ca48a42f3f64f10d23 to your computer and use it in GitHub Desktop.

Revisions

  1. howtomakeaturn created this gist Apr 12, 2019.
    18 changes: 18 additions & 0 deletions fp.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    changeOptionValue(optionIndex, valueIndex, newValue) {
    const state = this.state;

    const newState = {
    ...state,
    options: state.options.map((option, i) =>
    i === optionIndex ?
    { ...option, values: option.values.map((value, ii) =>
    ii === valueIndex ?
    newValue : value
    )
    } :
    option
    )
    };

    this.setState(newState)
    }