4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PR: JISOU | Reactプログラミングコーチング
AIで不安を感じたら!    JISOUメンバー募集中

【React】default exportなら無名関数でコンポーネント定義できる

4
Posted at

はじめに

  • たまたまIDEのコード補完で見つけた
  • こういうのを一つ一つ拾ってアウトプットしていると色んな事と繋がって覚えられて良い

内容

  • 以下のように定義できる
  • default exportなので当然使う側で名前を決められる
  • ただ、名前空間を決める恩恵があるのでnamed exportの方が使う機会は多そう。一つ階層構造にあそびがあるのがnamed exportの勝っている点かと
export default () => {
    const funcname = () => {何らかの処理}
    return (
        <>
            <p>hogehoge</p>
        </>
    )
}

終わりに

  • default exportはあくまでデフォルトだから、フォールバックして一意に定まる感じなのかなと思った
  • Laravelのシングルアクションコントローラーとか好きな人もいるし、読めて損はなさそう
  • named export, default expoertという名前の通りでやっぱり命名は大切だと思った
4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?