Open13

Remix に入門する

Koichi HayakawaKoichi Hayakawa

Webアプリを作るとき、思考停止でNext.jsを使用することが多かったが、最近は Remix を使っている事例も多く見かけるので、キャッチアップしてみる。

Remix 公式ドキュメント

https://remix.run/

Koichi HayakawaKoichi Hayakawa
Koichi HayakawaKoichi Hayakawa

とりあえず全部Yesを選択

 ✝  ~/src  npx create-remix@latest

Need to install the following packages:
  create-remix@2.9.2
Ok to proceed? (y) y
npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported

 remix   v2.9.2 💿 Let's build a better website...

   dir   Where should we create your new project?
         remix-first-app

      ◼  Using basic template See https://remix.run/guides/templates for more
      ✔  Template copied

   git   Initialize a new git repository?
         Yes

  deps   Install dependencies with npm?
         Yes

      ✔  Dependencies installed

      ✔  Git initialized

  done   That's it!

         Enter your project directory using cd ./remix-first-app
         Check out README.md for development and deploy instructions.

         Join the community at https://rmx.as/discord
Koichi HayakawaKoichi Hayakawa

とりあえずざっと流した。
Next.js 同様、デフォルトでtailwindcssが入っているのはよい。

Koichi HayakawaKoichi Hayakawa
Koichi HayakawaKoichi Hayakawa

action

action 関数が実行されると、loader が後続に呼ばれる様子。
refetch を意識しなくてもよさそう。
https://remix.run/docs/en/main/route/action

一つのコンポーネントで複数の mutation がある場合、action の中で条件分岐をすればよいのだろうか。もしくは、mutation (リソース?) の単位でコンポーネントを分けるべきなのか・・?

複数のリソースが混在するようなケースについて知りたい。

Koichi HayakawaKoichi Hayakawa

Note the weird _ in contactId_. By default, routes will automatically nest inside routes with the same prefixed name. Adding a trailing _ tells the route to not nest inside app/routes/contacts.contactId.tsx. Read more in the Route File Naming guide.

うーむ。。。ややこしい命名やなぁ。ファイル名長くなりがち?ちゃんと目を通さないと。