Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
個人的に楽しかった実装2022
Search
Azusa Okamoto
December 12, 2022
Programming
150
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
40
「わたし色」の見方で拓く世界
azunyan
0
29
ちゃんとSvelte, Hello Worldした!
azunyan
0
77
最近取り組んでいることについて喋ってみる
azunyan
0
24
フロントエンドエンジニアが関数型プログラミングに出会った話
azunyan
0
120
TECH WOMAN KANSAIの 取り組みと今後~2024年の振り返りと2025年へ~
azunyan
0
100
Go初心者が開発やってみた!
azunyan
1
580
デブサミウーマン2023 アウトプットって何が良いの?
azunyan
0
1.3k
TestCaféでE2Eテスト!
azunyan
0
160
Other Decks in Programming
See All in Programming
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
210
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
130
Foundation Models frameworkで画像分析
ryodeveloper
1
600
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
その節約、円になってますか?
isamumumu
1
710
Cloudflare is Agents
chimame
0
150
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
880
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
500
VibeCodingからAgenticWorkflowへ
starfish719
0
350
yield再入門 #phpcon
o0h
PRO
0
990
AIが無かった頃の素敵な出会いの話
codmoninc
1
400
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Test your architecture with Archunit
thirion
1
2.3k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.3k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
640
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The SEO Collaboration Effect
kristinabergwall1
1
520
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
260
Docker and Python
trallard
47
4.1k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
530
Evolving SEO for Evolving Search Engines
ryanjones
0
250
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年間でした!
ご清聴ありがとうございました!!