Closed26
TypeScript/Next.js/ChakraUIを使ったクソアプリを作る

最近筋トレにハマっているので、それを題材にしたクソアプリを作る。
React・TypeScriptの学習したいというのもあるので、Next.jsを使う。
CSS frameworkはChakra UIを選定。特別な理由はない。

アプリ名 KinniQ
筋トレに関するQuizを出し、正誤によって筋トレメニューを決定する。

画面遷移図
超シンプルだが、Reactは始めてだしフロントの技術もデザインも苦手なのでこれくらいで十分

プロジェクトのセットアップをしてみる
まずはNext.js + TypeScriptから
yarn next-app kinniq-frontend
早速失敗している

nodeのバージョンのせいだったのでnodenvで16.13.1を入れて解消

次にTypeScriptの導入
空のtsconfig.jsonを作成して yarn devを実行する
❯ touch tsconfig.json
❯ yarn dev
yarn run v1.22.17
$ next dev
warn - Port 3000 is in use, trying 3001 instead.
ready - started server on 0.0.0.0:3001, url: http://localhost:3001
It looks like you're trying to use TypeScript but do not have the required package(s) installed.
Please install typescript and @types/react by running:
yarn add --dev typescript @types/react
If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your pages directory).
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
言われた通りyarn add --dev typescript @type/react
を実行

既存のファイルを.ts/.tsxに変える

次はChakra UIを導入する

yarn add '@chakra-ui/react' '@emotion/react@^11' '@emotion/styled@^11' 'framer-motion@^5'
で必要なパッケージを導入。
その後、ドキュメント通りにChakraProvider
を_app.tsxに追記

とりあえずトップページのフォントとかが変わったが、もう少し何か書いて試してみる。

簡単なトップページをChakraUIコンポーネントで作ってみた
<Box>
<Box bg='orange' w='100%' p={4} color='white'>
<Text>This is KinniQ!!</Text>
</Box>
<Container>
<Text pt={5} fontSize='5xl' align='center'>
KinniQ
</Text>
<Box pt={10} align='center'>
このアプリケーションは筋肉に関する知識を問うクイズアプリです。
</Box>
<Center pt={7}>
<Button colorScheme="teal" color="white">
クイズに挑戦する
</Button>
</Center>
</Container>
</Box

ざっくりとドキュメントのどこを見て試行錯誤すればよいかはわかったので次に進む

できればeslintとprettierの導入もちゃんとやろう

まずはメインとなるクイズの画面とロジックを作っていくか
このスクラップは2024/02/18にクローズされました