Open12

reactとtypescriptでtodoアプリを作るメモ

minmegminmeg

create-react-appはメンテナがいなくて更新止まったのか…
Viteでいくぞ

https://vitejs.dev/guide/

Vite にはNode.jsバージョン 18 以降が必要です。

node --version
v18.12.1
npm create vite@latest RTtodo -- --template react-ts
✔ Package name: … rttodo

Scaffolding project in /Users/minmeg/workspace/RT-todo/RTtodo...

Done. Now run:

 cd RTtodo
 npm install
 npm run dev
minmegminmeg

Viteさんの指示に従ってみる

npm install

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/eslint-plugin@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/parser@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/scope-manager@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/type-utils@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/utils@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/visitor-keys@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/types@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@typescript-eslint/typescript-estree@7.3.1',
npm WARN EBADENGINE   required: { node: '^18.18.0 || >=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.12.1', npm: '8.19.2' }
npm WARN EBADENGINE }

いっぱい怒られている
nodeのバージョンを上げんといかんそう

minmegminmeg

バージョン管理ツールって結局何が正解なんだろうね…?
nとかnvmとか?
asdfとかaquaとか?

いったん普通にupdateしちゃおう
https://nodejs.org/en/download

node -v
v20.11.1

普通に行けたや、再チャレンジ

minmegminmeg
npm install   

up to date, audited 220 packages in 913ms

41 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

すっといけた&npm run devも動いたぞ

minmegminmeg

頻出するtypescriptの型説明のDoc、内容がまとまっててとてもいいな〜
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html

TypeScriptのinterfaceとtypeの違い
https://typescriptbook.jp/reference/object-oriented/interface/interface-vs-type-alias
型エイリアスの方が拡張性が少なそうで安全に倒せそうなので、悩んだら型エイリアスで良さそうだな

React.StrictModeについて。地味にこの辺はあんまり知らなかったな
https://ja.react.dev/reference/react/StrictMode

この辺りは自分でメモしよう