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
about-vue-hooks.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
sunecosuri
January 30, 2019
770
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
about-vue-hooks.pdf
sunecosuri
January 30, 2019
More Decks by sunecosuri
See All by sunecosuri
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
680
'Securing Web Apps with Modern Platform Features' を意訳してみる / Translate Securing Web Apps with Modern Platform Features
sunecosuri
2
390
Vue.js × TypeScript でclass style componentを廃止した話 / migrated-class-style-component -for-vuejs-and-typescrpit
sunecosuri
2
4.4k
Nuxt.js のbuid速度が早くなるオプションのいくつかについて / Increase-build-speed-for-Nuxt.js
sunecosuri
1
1.4k
Nuxt.js におけるCSPの連携について / content security policy for Nuxt.js
sunecosuri
0
2.6k
ロリポップマネージドクラウドでAlexaスキルを開発しよう / let's development alexa skill by lolipop managed cloud
sunecosuri
1
240
マネージドクラウドのリリース速度を上げるお話 / Increase release speed for managed cloud
sunecosuri
2
370
Reconsider Content Security Policy for WEB Application
sunecosuri
0
120
Featured
See All Featured
Music & Morning Musume
bryan
47
7.2k
Rails Girls Zürich Keynote
gr2m
96
14k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
300
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
The browser strikes back
jonoalderson
0
1.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Prompt Engineering for Job Search
mfonobong
0
340
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Transcript
Vue-hooks Vue hooks ʹ͍ͭͯ @sunecosuri Date: 2019-01-30 Vue Night in
Fukuoka #2
@sunecosuri(Narumi Kouki) GMOϖύϘΤϯδχΞ ϚΠϒʔϜɿ ϝϧνϟϦܯʢ์ஔࣗసंΛ͢ʣ Ͱ͔͍ʢେެԂʣۙͰ͔Θ͍͍ݘʹରͯ͠৮Βͤͯ͘Εͱֻ͚ࣄҊ
͢͜ͱ Vue-hooks ʹ͍ͭͯ ෦࣮ʹ͍ͭͯ React-hooks ʹ͍ͭͯ mixin ʹ͍ͭͯ
Vue hooks Vue hooks
Vue hooks Vue Hooks Evan You(Vueͷ։ൃऀ)͞ΜͷVueͰ React hooks ͷΑ͏ʹ࣮͞Ε͍ͯΔ࣮ݧతͳϦϙδτϦ ※
͢Ͱʹnpm publish ͞Ε͍ͯΔ͕production ೖඇਪͱͷ͜ͱʢݱ࣌Ͱ0.3.2ʣ
React hooks React hooks
React hooks React Hooks ReactͰStateful ͳίϯϙʔωϯτΛॻ͘ࡍɺClass ComponentΛΘͳ͚ΕͳΒͳ͔͕ͬͨ State Λ Functional
Component Ͱѻ͑ΔΑ͏ʹͨ͠ͷ
ͳʹ͕͍͍ͷʁ
ͳʹ͕͍͍ͷ͔ Vue ͷ ݱࡏͷAPI ʹมΘΔͷͱݴ͏ΑΓɺMixin ͷҙຯ߹͍ʹ͍ۙ
Mixin Mixin ί ϯ ϙ ʔ ω ϯ τ ʹ
ڞ ௨ ػ ೳ Λ Ճ ͢ Δ Έ - methods ʹڞ௨ؔͷՃ - lifecycle hook ʹ͓͚Δॲཧͷڞ௨Խ - created ͳͲͷϥΠϑαΠΫϧϑοΫʹڞ௨ॲཧՃ ϥΠϑαΠΫϧϝιουϛοΫεΠϯˠίϯϙʔωϯτͷॱʹ࣮ߦ͞ΕΔ - namespace͕ڝ߹ͨ͠ࡍίϯϙʔωϯτଆ͕༏ઌతʹ࣮ߦ͞ΕΔ ʢৼΔ͍తʹ্ॻ͖Ͱͳ͘Mergeʣ - ίϯϙʔωϯτʹΦϓγϣϯͷΑ͏ͳܗͰࠞͥࠐ·ΕΔ ※্هͷΑ͏ʹॻ͘ͱɺϩʔυ࣌ʹ ‘loaded mixin’ -> ’loaded main’ͷॱͰग़ྗ͞ΕΔ
mirin mixin ͷσϝϦοτ ҉ త ͳ ڍ ಈ ʹ
ͳ Γ ͢ ͍ ͨ Ί ɺ ό ά Λ ੜ Έ ͩ ͠ ͢ ͍ Օ ॴ ʹ ͳ Γ ͢ ͍ m i x i n Ͱ ڞ ௨ Խ ͠ ͯ ί ʔ υ Λ ͠ ͯ ͍ Δ ͷ ʹ ɺ ؔ ৺ ͞ Ε ʹ ͘͘ ͳ Γ ͕ ͪ ͳ ͷ Ͱ ໋ ໊ ॲ ཧ ͦ ͷ ͷ Λ ҙ ࣝ ͠ ͨ Γ ͢ Δ ඞ ཁ ͕ ͋ Δ
Vue Hooks API Vue Hooks API API໊ ༰ useEffect ϥΠϑαΠΫϧΠϕϯτΛ࣮ݱ͢ΔجװͱͳΔAPI
useRef Instance.$refs Λฦ͢ useData localStateΛఆٛ Vueͷdata૬ instance.$set() Ͱ࣮ useMounted useEffectΛੜͤͯ͞mounted()Λ࣮ useDestroyed useEffectΛੜͤͯ͞destroyed()Λ࣮ useUpdated useEffectΛੜͤͯ͞updated()Λ࣮ useWatch instance.$watch Λ෦Ͱ࣮ߦͯ͠ҾΛฦ͢ useComputed instance.$watch Λ෦Ͱ࣮ߦͯ͠ɹinstance. _computedStore Λฦ͢ withHooks ͜ͷؔʹ͞ΕͨؔͰͷΈ্هͷHookΛݺͼग़͢͜ͱ͕Ͱ͖Δ
͜Μͳ෩ʹॻ͚Δ (ΧελϜϑοΫver) 1. vue-hooks͔Β ར༻͢Δ hooks Λ import 2. useComputed,
useWatch, useMountedͱ͔Λ༻͍ͯదٓॲཧΛՃ 3. ΧελϜϑοΫΛఆٛ͢Δ 4. hooks() ෦ͰΧελϜϑοΫͷฦΓΛฦ͢ 5. render method ෦ͰwithHooks ͷΓʢΧελϜϑοΫʣΛݺͼग़͢
͜Μͳ෩ʹॻ͚Δ (ैདྷͷVueίϯϙʔωϯτver) 1. vue-hooks͔Β ར༻͢Δ hooks Λ import 2. useDataΛͬͯΦϒδΣΫτͷܗͰఆٛ͢Δ
3. hooks() ෦ͰuseComputed, useWatch, useMountedͱ͔Λ༻͍ͯద ٓॲཧΛՃ 4. templateଆͰར༻͢ΔΛreturn͢Δ
Demo Demo
ײ ͱ ·ͱΊ - Vue3.X ͰVueMixin ͔Β Vue hooks APIʹஔ͖͑Δ͜ͱΛલ͖ʹݕ౼ͯͦ͠͏
- Hooks ΛͬͯίϯϙʔωϯτΛؔԽ͢Δ͜ͱͰείʔϓΛԚ͞ͳ͍ - useEffects() Λ͏ͱΑΓॊೈʹΧελϜϑοΫΛͰ͖ͯڞ௨ͷϩδοΫॲཧΛؔͱ ͯ͢͠Δ͜ͱ͕Ͱ͖ͦ͏ ʢͱ͍͑React hooksྗ͕ͳ͍ͷͰɺڧ͍ํੋඇڭ͍͑ͯͩ͘͞ʂʣ - ࢀߟ: https://qiita.com/c6h4clch3_gh/items/424a6ceba8148456ae67
Thanks Thanks!