15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【React】同じpropsから複数のローカル変数を取り出す時は、分割代入が便利な件

Last updated at Posted at 2022-10-31

はじめに

タイトル通りなのですが、同じpropsから複数のローカル変数を取り出す時は、
分割代入が非常に便利です。

分割代入

このようなコードがあるとします。

export const CompanyPanel = memo((props: Props) => {
  const id = props.company.id;
  const name = props.company.name;
  const deleted = props.company.deleted;

分割代入を使うと…

export const CompanyPanel = memo((props: Props) => {
  const { id, name, deleted } = props.company;

このように省略してスッキリと書くことができるので便利です。

参考

15
16
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
15
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?