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
誰でもわかる!React入門
Search
azurata
November 24, 2022
Technology
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
誰でもわかる!React入門
先輩に「わかった気になれた」と評されたLTです。
azurata
November 24, 2022
More Decks by azurata
See All by azurata
この夏始めたい 「TOPPERS/ASP3」
azurata09
0
62
SPAJAM2022
azurata09
0
130
etrobo2022 Shiokara-z Model
azurata09
0
1.1k
SuggIt!
azurata09
0
120
この前出たハッカソンでVue.jsを使った話
azurata09
1
320
Other Decks in Technology
See All in Technology
Snowflakeのコスト最適化を支えるアーキテクチャ設計
ktatsuya
1
1.5k
2026-09-09 【sigma_ucj#1】Sigma を IaC 管理したい! / IaC for Sigma
civitaspo
0
120
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
410
Sigmaで作る業務アプリ
kazushiro_honma
0
120
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
2
140
From Vanilla Kubernetes to a Batteries-Included Platform: Developer Experience at 1,300+ Clusters
yosshi_
0
680
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1.1k
enechainの内製セルフサービスプラットフォーム
hiyosi
0
160
Tab5をRubyで動くパソコンにする
kishima
2
340
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
140
AI時代だからこそ、スケールしないことをやろう
yutashigemura
1
150
なぜSRE・セキュリティは評価されないのか?守りの組織を事業成長エンジンに変えた実践
cscengineer
PRO
3
2.5k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Deep Space Network (abreviated)
tonyrice
0
300
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Music & Morning Musume
bryan
47
7.4k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
350
Joys of Absence: A Defence of Solitary Play
codingconduct
1
500
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
980
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
290
Transcript
୭ͰΘ͔Δʂ Reactೖ ʙReactͱ͍͏ΑΓϞμϯϑϩϯτͷͬΆ͘ͳͬͪΌͬͨʙ ͋ͣΒͨ (@azurata09_)
લఏࣝ • HTML͕ॻ͚Δ • JSॻ͚Δͱͳ͓ྑ͠
Ϟμϯϑϩϯτ ಋೖฤ
JSΛͬͯHTMLΛॻ͖ସ͑ͯΈΔ <h1>Hello, HTML!</h1> <script> const h1_element = document.getElementsByTagName("h1")[0] h1_element.innerHTML =
"Hello, JS!" </script>
DOM͔Βh1λάͷཁૉΛͱ͖ͬͯͯ <h1>Hello, HTML!</h1> <script> const h1_element = document.getElementsByTagName("h1")[0] h1_element.innerHTML =
"Hello, JS!" </script>
தΛॻ͖ସ͑Δ <h1>Hello, HTML!</h1> <script> const h1_element = document.getElementsByTagName("h1")[0] h1_element.innerHTML =
"Hello, JS!" </script>
·ͩΘ͔Δ
ͪΐͬͱ༰૿ͯ͠ΈΔ <div> <input type="text" value=“hello!”> <p></p> <p></p> </div> <script> const
input = document.getElementsByTagName("input")[0] const p1 = document.getElementsByTagName("p")[0] const p2 = document.getElementsByTagName("p")[1] function inputHandler() { p1.innerHTML = input.value p2.innerHTML = input.value.toUpperCase() } input.addEventListener("input", inputHandler) inputHandler() </script>
DOM͔ΒͦΕͧΕཁૉΛ͖࣋ͬͯͯ <div> <input type="text" value=“hello!”> <p></p> <p></p> </div> <script> const
input = document.getElementsByTagName("input")[0] const p1 = document.getElementsByTagName("p")[0] const p2 = document.getElementsByTagName("p")[1] function inputHandler() { p1.innerHTML = input.value p2.innerHTML = input.value.toUpperCase() } input.addEventListener("input", inputHandler) inputHandler() </script>
Πϕϯτϋϯυϥ࡞Δ <div> <input type="text" value=“hello!”> <p></p> <p></p> </div> <script> const
input = document.getElementsByTagName("input")[0] const p1 = document.getElementsByTagName("p")[0] const p2 = document.getElementsByTagName("p")[1] function inputHandler() { p1.innerHTML = input.value p2.innerHTML = input.value.toUpperCase() } input.addEventListener("input", inputHandler) inputHandler() </script>
ΪϦΘ͔Δ
Ͱ͜Ε͕Կඦߦʹ͍ͬͯΔͱ…
Vanilla JSͷ • දࣔ(HTML)ͱϩδοΫ(JS)͕ผͷॴʹ͋Δ • ϩδοΫ໋͕ྩతͰHTMLͱ૬ޓʹඥ͔ͳ͍ • (HTMLΛ͔·͢ͱ)༰ͷ࠶ར༻͕؆୯ʹͰ͖ͳ͍
વੜ͡Δ͓ؾ࣋ͪ • HTMLڬΉͱ໘͔ͩΒJS͚ͩͰϑϩϯτΓ͍ͨʂ
͍ͩͿલʹΓ߹͍͕LTͯͨ͠
༰ཁ • JS͚ͩͰWebαΠτ ࡞Γ·ͨ͠ʂ
։͍ͯΈΔ • https://ryu1-1uyr.github.io/html_oasobi/ phase_6.html • https://github.com/ryu1-1uyr/html_oasobi/blob/ master/phase_6.html
ίʔυΛݟΔͱ… 100ߦҎ্ͷίʔυͰ ࣮͞ΕͯΔ
Ͱ… • ͋ͳͨ͜ΕΛ࣮͍ͨ͠ͱࢥ͍·͔͢ʁ • ݏͰ͢
HTMLͷ͍͍ͱ͜Ζ • ߏͳͷͰߏ͕Θ͔Γ͍͢ • DOMͰݕࡧ • ίʔυ͚ͩͰݟ͕ͨ૾Ͱ͖Δ
ڪΒ͘։ൃऀ͜͏ߟ͑ͨ • Ͳ͏ʹ͔දࣔͱϩδοΫΛҰॹʹͰ͖ͳ͍ͩΖ͏͔ • ͋ΘΑ͘࠶ར༻Մೳʹ͍ͨ͠…
ڪΒ͘։ൃऀ͜͏ߟ͑ͨ • Ͳ͏ʹ͔දࣔͱϩδοΫΛҰॹʹͰ͖ͳ͍ͩΖ͏͔ • ͋ΘΑ͘࠶ར༻Մೳʹ͍ͨ͠… 㱺 ϝλϓϩάϥϛϯάͰղܾ͢Δ
ReactͰ։ൃऀ͕Δ͜ͱ • ίϯϙʔωϯτͱ͍͏୯ҐͰϓϩάϥϜΛॻ͘ • ίϯϙʔωϯτΛΈ߹Θͤͯίϯϙʔωϯτ Λ࡞Ͱ͖Δ • ίϯϙʔωϯτΛΈ߹ΘͤΔ͜ͱͰDOMಉ༷ͷ ""Λ࡞͢Δ
React͕ͬͯ͘ΕΔ͜ͱ • ίϯϙʔωϯτΛಡΈࠐΜͰHTML+JSʹॻ͖ى͜͢ • ͭ·ΓʮϓϩάϥϜͰϓϩάϥϜΛੜ͢Δʯ • ͜Ε͕ϝλϓϩάϥϛϯά
͔ͩΒReactެࣜνϡʔτϦΞϧͰ ͜Μͳίʔυ͕ग़Δ return React.createElement('div', {className: 'shopping-list'}, React.createElement('h1', /* ...
h1 children ... */), React.createElement('ul', /* ... ul children ... */) );
Reactೖฤ
Reactͷجຊ • ؔΦϒδΣΫτͰίϯϙʔωϯτΛهड़͍ͯ͘͠ • ؔίϯϙʔωϯτͱ͍͏
جຊܗ import React from "react" function App() { return( <>
<h1>Hello, React!</h1> </> ) } export default App
ΞϩʔؔͰఆٛͨ͠ํ͕ݎ࿚ (constʹ͢Δ͜ͱͰॻ͖͑ΒΕͳ͘ͳΔ) import React from "react" const App = ()
=> { return( <> <h1>Hello, React!</h1> </> ) } export default App
TSͳΒܕ໌ࣔ (͜Εͳͯ͘ಈ͔͘) import React from "react" const App = ():
JSX.Element => { return( <> <h1>Hello, React!</h1> </> ) } export default App
ଞͷίϯϙʔωϯτͬͯΈΔ import React from "react" import { OtherComponent } from
"./OtherComponent.jsx" const App = (): JSX.Element => { return( <> <h1>Hello, React!</h1> <OtherComponent /> </> ) } export default App
React Hooksͱʁ • ؔίϯϙʔωϯτ୯ମͩͱͰ͖Δ͜ͱ͕গͳ͍ • ࠷ॳදࣔʹؔ͢Δ͜ͱ͔͠ॻ͚ͳ͔ͬͨ • ΫϥείϯϙʔωϯτͷػೳΛؔίϯϙʔωϯτ Ͱهड़Ͱ͖ΔΑ͏ʹͨ͠ͷ͕React Hooks
Hooksͬͯ200छྨ ͋ΜͶΜ(ͳ͍) ͳΜ͔͍ͬͺ͍͋Δ ͳͷͰྲྀੴʹجຊͷͭͰ צห
useState • ReactͷؔίϯϙʔωϯτͰɺී௨ͷมʹΛ ೖͯ͠࠶Ϩϯμʔ͞Εͳ͍ • ͦͷͨΊɺߋ৽+࠶ϨϯμʔΛ͢Δػߏ͕ඞཁ • ͦΕ͕useState
useStateͷྫ import React, { useState } from 'react'; function Example()
{ const [count, setCount] = useState(0); return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}> {/* ΫϦοΫ͢Δ͝ͱʹ1૿͑Δ */} Click me </button> </div> ); }
useE ff ect • ෭࡞༻ϑοΫͱݺΕΔ • ୈ2Ҿґଘ͢Δ(͍͍ͨͯState)ͷྻΛ͢ • ୈ2Ҿͷதʹ͋Δ͕มߋ͞ΕΔʹ࣮ߦ͞ΕΔ •
ۭྻΛ͢͜ͱͰ࠷ॳͷҰͷΈ࣮ߦ͢Δ͜ͱ͕Ͱ͖Δ • ٯʹԿ͚ͭͳ͍ͱશͯͷ͕ߋ৽͞ΕΔʹ࣮ߦ͞ΕΔ
useE ff ectͷྫ import React, { useState, useEffect } from
'react'; function Example() { const [count, setCount] = useState(0); useEffect(() => { document.title = `You clicked ${count} times`; // ࠶Ϩϯμʔ͞ΕΔʹݺΕΔ }); return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}>Click me</button> </div> ); }
useE ff ectͷྫ import React, { useState, useEffect } from
'react'; function Example() { const [count, setCount] = useState(0); useEffect(() => { document.title = `You clicked ${count} times`; // Ұ͔͠ݺΕͳ͍ }, []); return ( <div> <p>You clicked {count} times</p> <button onClick={() => setCount(count + 1)}>Click me</button> </div> ); }
useContext • ͬͨ͜ͱ͕ͳ͍ 🤯 • ωετ͞Εͨࢠίϯϙʔωϯτʹରͯ͠σʔλ ΛϒνࠐΊΔΒ͍͠ • όέπϦϨʔ͠ͳͯ͘Α͍ʂ •
Α͘Θ͔Μͳ͍ͷͰྫলུͤͯ͞΄͍͠
·ͱΊ • ϞμϯϑϩϯτͰJavaScriptϑϨʔϜϫʔΫ͕ ΘΕΔཧ༝࠶ར༻ՄೳͳίʔυΛੜΈग़ͤΔ͔Β • ࠷ۙͷReactͰؔܕίϯϙʔωϯτͰίϯϙʔωϯτΛ هड़͍͖ͯ͠ɺReactͷػೳΛReact HooksͰར༻͢Δ
ࢀߟจݙ • https://qiita.com/Yametaro/items/ 3c27305072464e1d6230 • https://speakerdeck.com/s17001/huremuwakufalseqi- chi-tininaritakatuta • https://github.com/ryu1-1uyr/html_oasobi •
https://ja.reactjs.org/docs/hooks-overview.html