0
0

More than 3 years have passed since last update.

Javascriptの分割代入について

Posted at

Reactを触っていて下のように突然{}の引数が出てきて「なんだこれ??」となりました。

onSortEnd = ({oldIndex, newIndex}) => {
    this.setState(({items}) => ({
      items: arrayMove(items, oldIndex, newIndex),
    }));
  };
  render() {
    return <SortableList items={this.state.items} onSortEnd={this.onSortEnd} />;
  }

結論

これは分割代入と呼ばれるものらしくて、以下と同じみたいです。要は、オブジェクトが渡されていて{}とすることで勝手に代入してくれているみたいです。


function onSortEnd(param){
  let oldIndex = param.oldIndex
  let newIndex = param.newIndex
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0