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
190
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
63
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
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
360
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
210
Incremental HTTP
kazuho
5
2.1k
初対面のメンバーがチームを組み、Claude Codeでゼロからサービスをリリース
mkdev10
1
110
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
130
AIは爆速なのに、私が詰まっていた話 ― 音声入力と鳴くマスコットでボトルネックを削る
yama3133
0
550
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
120
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
680
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
17
120k
FOSS4Gを活用した自治体業務DXの試み
470715
0
120
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
130
Lambda MicroVMsが分からなすぎたので使い所を1から考えてみた
tsukuboshi
2
430
Featured
See All Featured
Thoughts on Productivity
jonyablonski
76
5.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
320
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
It's Worth the Effort
3n
188
29k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
30 Presentation Tips
portentint
PRO
1
420
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
460
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
450
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