Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
個人的に楽しかった実装2022
Search
Azusa Okamoto
December 12, 2022
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
個人的に楽しかった実装2022
Azusa Okamoto
December 12, 2022
More Decks by Azusa Okamoto
See All by Azusa Okamoto
GraphQLでAPI開発 やってみよう!
azunyan
0
49
「わたし色」の見方で拓く世界
azunyan
0
33
ちゃんとSvelte, Hello Worldした!
azunyan
0
86
最近取り組んでいることについて喋ってみる
azunyan
0
28
フロントエンドエンジニアが関数型プログラミングに出会った話
azunyan
0
130
TECH WOMAN KANSAIの 取り組みと今後~2024年の振り返りと2025年へ~
azunyan
0
110
Go初心者が開発やってみた!
azunyan
1
590
デブサミウーマン2023 アウトプットって何が良いの?
azunyan
0
1.3k
TestCaféでE2Eテスト!
azunyan
0
160
Other Decks in Programming
See All in Programming
すこし踏み込む CancellationToken
htkym
2
1.7k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
22
22k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1k
Railsバージョンを4倍にした話
optim
0
190
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
290
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
490
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
250
JIS keyboard support in Omarchy
lef237
0
100
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
350
mrbgem 三角測量 開発
ogom
0
240
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
Scaling GitHub
holman
464
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Automating Front-end Workflow
addyosmani
1369
210k
30 Presentation Tips
portentint
PRO
1
430
Abbi's Birthday
coloredviolet
4
10k
Evolving SEO for Evolving Search Engines
ryanjones
0
320
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
410
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Transcript
個人的に楽しかった実装 2022 あずにゃん 20221211_TECH WOMAN KANSAI_クリスマス勉強会
今日お話しすること 今年1年で、 個人的に「できて良かったな〜」と思う実装について!
今日お話しすること 1. React Hook Formで動的フォーム 2. Express×React×PostgreSQL 3. まとめ 都合により、一部型指定
を省略してます!
1. React Hook Formで動的フォーム 2. Express×React×PostgreSQL 3. まとめ
React Hook Form Reactで簡単にフォームを作成できるライブラリ。 入力した値の取得やバリデーションなどを行える。
None
< > < > </ > < {... ( )}
/> < > < /> < { ( )} /> </ > </ > form label label input div div form タスク: register handleSubmit submitForm 'title' '登録' BackToHomeButton SubmitButton onClick text = = 基本のフォーム〜JSX〜 入力値の登録 フォーム送信実行
const => const const => div div = () {
, , , = (); = ( : ): { (); }; ( ~略~ ); }; SampleForm register handleSubmit watch reset useForm submitForm reset { } // フォーム送信 // 後ほどデータベースへの追加処理を行う // フォームを空にする。 data any void return < > </ > 基本のフォーム〜処理〜
動的フォーム
const => const const = () { , , ,
= ({ : : : }); , , = ({ , : }); ~略~ ( ~略~ ); }; SampleDynamicForm register handleSubmit reset useForm { } prepend append useFieldArray { } { '' } { } 'sample' control [ ] fields defaultValues sample title control name // 入力値を格納するオブジェクトのキー名となる return 動的フォーム〜処理〜 デフォルト値が入ったオブジェクトを要素とする配列
< > < = </ > < > < >
</ > < > < { ( )} /> </ > </ > < = </ > </ > form button => button => div label label div input $ div div button => button form {() ( )}>先頭に追加 . (( : , : ) ( タスクNo.{ }: ... )) {() ( )}>後ろに追加 ~略~ type onClick title: field index key field id index . index . type onClick title: "button" { ''} { { } `sample title` } "button" { ''} = = = prepend map register { } append fields any number . 動的フォーム〜JSX〜 配列を展開していく
フォーム送信すると... sampleオブジェクト 配列! フィールド単位 の中に、 ↓ で 配列の要素となっている!
完成したフォーム、実演してみる。
1. React Hook Formで動的フォーム 3. まとめ 2. Express×React×PostgreSQL
Express×React×PostgreSQL ・バックエンド →Express ・データベース →PostgreSQL ・フロントエンド →React pg-promiseという ライブラリを使うよ〜!
今回使うSQL文 ① 追加 INSERT INTO テーブル名(カラム名) VALUES(値) ② 取得(全件) SELECT
* FROM テーブル名 ③ 削除 DELETE FROM テーブル名 WHERE カラム名 = 値
PostgreSQLの実行〜接続〜 const const const = ( )(); = { .
. , . . , . . , . . , . . }; = ( ); pgp connectionConfig DB_HOST DB_PORT DB_DATABASE DB_USER DB_PASSWORD, db connectionConfig require pgp 'pg-promise' // DB接続に必要な情報 // DB接続 host: processenv port: processenv database: processenv user: processenv password:processenv
PostgreSQLの実行〜実行〜 // リクエストボディとして渡された値を取得 // 実行したいSQL文を事前に作成 // 実行 const const =>
= . . ; = ; . ( , ) . ( { . ( ); . ( ); }); title sql db sql [title] reqbodytitle data console data res data 'INSERT INTO tasks(title) VALUES($1)' manyOrNone then log send pg-promiseでは、返される結果の多さに応じて、メソッドを使いわけ!
PostgreSQLの実行〜例〜 const const => const const => = ( );
= (); ~略~ . ( , ( , ) { = . . ; = ; . ( , ) . ( { . ( ); . ( ); }); }); express app app title sql db sql [title] require express post manyOrNone then log send 'express' '/addTask' 'INSERT INTO tasks(title) VALUES($1)' req res reqbodytitle data console data res data
フォーム送信とデータ追加~ReactでAPI実行~ const async => const const = ( : ):
< > { : = { : . }; = . ( , ); . ( ); (); }; submitForm post log reset data title datatitle console any Promise void AddTaskParamType param response axiosClient param response // データベースに追加するAPI実行 // フォームを空にする。 await '/addTask'
フォーム送信とデータ追加、実演してみる。
1. React Hook Formで動的フォーム 2. Express×React×PostgreSQL 3. まとめ
まとめ ・useFieldArrayを用いて、フィールドを増減させられる フォームを作成できた (感動したw) ・データベース操作やってるの、面白いな〜と思った ・個人でバックエンドを経験できたこと自体が感動
まとめ ・他にも、Next.jsやmicroCMS、Svelte触ったりとか、 色々な技術に触れた1年間でした!
ご清聴ありがとうございました!!