Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ToDoアプリで学ぶReact/Redux入門/vtecx2_lt2

nishina
November 29, 2017

 ToDoアプリで学ぶReact/Redux入門/vtecx2_lt2

初心者歓迎!React勉強会+LT大会 https://vtecx.connpass.com/event/70544/
の発表資料です

参考リンク
・ソースコード
https://github.com/nishina555/todo-react
https://redux.js.org/docs/basics/ExampleTodoList.html

nishina

November 29, 2017
Tweet

More Decks by nishina

Other Decks in Programming

Transcript

  1. ֶशίετ͕௿͍ͱ͍͏ϝϦοτ MVCͷViewͷ໾ׂΛ୲͏JavaScript ϥΠϒϥϦ σʔλΛड͚औΓɺߋ৽͕ඞཁͳ෦෼ͷDOMΛ ಈతʹมߋ͢Δ Ծ૝DOMΛ࣋ͭ Reactͷಛ௃ʹ͍ͭͯ ਌͔Βࢠ΁propsΛܦ༝ͨ͠୯Ұํ޲ͷσʔλϑϩʔ ֤Component͸stateͰঢ়ଶΛ؅ཧ 

    Componentͷ૊Έ߹ΘͤʹΑͬͯΞϓϦΛߏ੒͢Δ ΞϓϦΛύʔπԽ͢Δ͜ͱͰ؅ཧ͕͠΍͘͢ͳΔ Componentͷ૊Έ߹ΘͤʹΑͬͯΞϓϦΛߏ੒͢Δ ΞϓϦΛύʔπԽ͢Δ͜ͱͰ؅ཧ͕͠΍͘͢ͳΔ
  2. Ծ૝DOMʹ͍ͭͯ(1/2) " $ QSPQT # & ' QSPQT QSPQT QSPQT

    % QSPQT ) QSPQT ਌͔Βࢠ΁propsΛܦ༝ͨ͠୯Ұํ޲ͷσʔλϑϩʔ ( DPNQPOFOU TUBUF TUBUF QSPQT 
  3. Ծ૝DOMʹ͍ͭͯ(2/2) " $ FWFOU # & ' FWFOU FWFOU FWFOU

    % FWFOU ) FWFOU ࢠ͔Β਌΁σʔλΛ౉͢ࡍ͸Πϕϯτ(click, mouse over, ͳͲ)ʹ ίʔϧόοΫΛ࣮૷ ( FWFOU 
  4. ToDoΞϓϦΛԾ૝DOMͰදݱ͢Δ "QQ 5P%P-JTU QSPQT 'PSN 5P%P QSPQT PO4VCNJU App͕todosͱ͍͏todoͷ·ͱ·ΓΛ؅ཧ͍ͯ͠Δ UPEPT\UPEP

    UPEP UPEPʜ^ pMUFS"MM UPEPJE UPEPUJUMFཛΛങ͏ UPEPTUBUVT"DUJWF App͔Βࢠʹରͯ͠propsͰσʔλΛ౉͢ Form͔ΒonSubmitͷΠϕϯτΛհͯ͠todo͕௥Ճ͞ΕΔ 
  5. ToDoΞϓϦΛԾ૝DOMͰදݱ͢Δ "QQ 5P%P-JTU QSPQT 'PSN 5P%P QSPQT PO4VCNJU App͕todosͱ͍͏todoͷ·ͱ·ΓΛ؅ཧ͍ͯ͠Δ UPEPT\UPEP

    UPEP UPEPʜ^ pMUFS"MM UPEPJE UPEPUJUMFཛΛങ͏ UPEPTUBUVT"DUJWF App͔Βࢠʹରͯ͠propsͰσʔλΛ౉͢ Form͔ΒonSubmitͷΠϕϯτΛհͯ͠todo͕௥Ճ͞ΕΔ 
  6. (࠶ܝ)ToDoΞϓϦΛԾ૝DOMͰදݱ͢Δ "QQ 5P%P-JTU QSPQT 'PSN 5P%P QSPQT PO4VCNJU App͕todosͱ͍͏todoͷ·ͱ·ΓΛ؅ཧ͍ͯ͠Δ UPEPT\UPEP

    UPEP UPEPʜ^ pMUFS"MM UPEPJE UPEPUJUMFཛΛങ͏ UPEPTUBUVT"DUJWF App͔Βࢠʹରͯ͠propsͰσʔλΛ౉͢ Form͔ΒonSubmitͷΠϕϯτΛհͯ͠todo͕௥Ճ͞ΕΔ 
  7. ReactͰͷঢ়ଶ؅ཧɾߋ৽ͷ໰୊఺ "QQ 5P%P-JTU 'PSN 5P%P PO$MJDL PO4VCNJU ToDoΛ׬ྃͤͨ࣌͞ͷσʔλͷมߋ͸ͲͷΑ͏ʹม͑Δʁ PO$MJDL ɾComponentؒͰσʔλͷड͚౉͠ɺঢ়ଶ؅ཧ͕ෳࡶԽ


    ɾReact͸Viewͷ໾ׂʹಛԽ͍ͯ͠ΔͨΊঢ়ଶ؅ཧ͸ۤख ྫ͑͹todoΛ׬ྃͤͨ͞৔߹ɺtodoΛ؅ཧ͢ ΔtodosΛߋ৽͢ΔͨΊʹίʔϧόοΫ͕Կ౓ ΋࣮ߦ͞ΕΔ 
  8. Fluxͷঢ়ଶ؅ཧϞσϧʹ͍ͭͯ: ֓ཁ Action -> Dispatcher -> Store -> ViewͷҰํ޲Ͱ σʔλͷঢ়ଶ͕఻ൖ(Լͷ໼ҹ)

    ϢʔβʔͷߦಈʹΑͬͯView͔ΒActionΛൃߦ͠ɺ
 σʔλͷঢ়ଶΛ఻ൖͤ͞Δ͜ͱ΋Ͱ͖Δ(্ͷ໼ҹ)