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
sunecosuri
January 30, 2019
780
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
830
'Securing Web Apps with Modern Platform Features' を意訳してみる / Translate Securing Web Apps with Modern Platform Features
sunecosuri
2
400
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
250
マネージドクラウドのリリース速度を上げるお話 / Increase release speed for managed cloud
sunecosuri
2
370
Reconsider Content Security Policy for WEB Application
sunecosuri
0
130
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
So, you think you're a good person
axbom
PRO
2
2.1k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
260
Deep Space Network (abreviated)
tonyrice
0
270
Six Lessons from altMBA
skipperchong
29
4.5k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Making the Leap to Tech Lead
cromwellryan
135
10k
Why Our Code Smells
bkeepers
PRO
340
58k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.1k
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!