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
誰でもわかる!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
310
Other Decks in Technology
See All in Technology
作り直せるコードは迅速に 作り直せないDBは慎重に - AI時代のプロダクトエンジニアが「判断の不可逆性」で開発速度を変える話
kinosuke01
0
250
少人数データチームのDevin活用実践事例
runandy16
2
450
Bet AI Day 2026丨Agentは、「金融」という巨大産業の何を変えられるのか
layerx
PRO
0
1k
プロダクト思考 × 基盤思考を AIで実現する Compound Engineering
tkc66buzz
1
270
KAEN Company Deck
kaen
PRO
0
320
AndroidでHDRメディアを「壊さずに」扱う
chigichan24
0
410
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
150
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
110
Webとヘルスデータ
yukukotani
0
190
20260906 「AWS運用入門」著者が教える、運用業務への生成AI活用入門
masaruogura
0
240
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
110
PM領域でのAI Agentの活用
lycorptech_jp
PRO
0
270
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
400
Rails Girls Zürich Keynote
gr2m
96
14k
Crafting Experiences
bethany
1
290
Designing for Performance
lara
611
70k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Mind Mapping
helmedeiros
1
350
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Designing Experiences People Love
moore
143
24k
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