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
Nokogiri
April 16, 2017
Technology
2
610
怖くないReact
2017年4月19日 ReactHandon イベント向けのPPT
中で紹介しているレポジトリ
https://github.com/nokogiring/ReactLogoGenerator
Nokogiri
April 16, 2017
Tweet
Share
More Decks by Nokogiri
See All by Nokogiri
React Testing Libraryでの WAI-ARIAロールの活用事例
undefined_name
1
120
自動テストは何の役に立つのか そして役に立たないのか
undefined_name
5
1.7k
Pipe Operator (|>) の紹介
undefined_name
2
270
FizzBuzzで学ぶOCP
undefined_name
0
87
エンジニアとQAでコラボするフロントエンドリアーキテクチャ開発の事例
undefined_name
4
2.7k
オブジェクト指向のプラクティスをフロントエンドで活用する
undefined_name
7
1.5k
モププロ@kintone開発チーム
undefined_name
1
550
勉強会で登壇者に 質問しづらい課題を解決する サービスをリリースしました🎉
undefined_name
2
1.2k
Usefull GitLens
undefined_name
3
770
Other Decks in Technology
See All in Technology
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
17
45k
Goで作って学ぶWebSocket
ryuichi1208
3
2.3k
Apache Iceberg Case Study in LY Corporation
lycorptech_jp
PRO
0
130
「海外登壇」という 選択肢を与えるために 〜Gophers EX
logica0419
0
900
白金鉱業Meetup Vol.17_あるデータサイエンティストのデータマネジメントとの向き合い方
brainpadpr
7
910
システム・ML活用を広げるdbtのデータモデリング / Expanding System & ML Use with dbt Modeling
i125
1
260
全文検索+セマンティックランカー+LLMの自然文検索サ−ビスで得られた知見
segavvy
2
130
Raycast AI APIを使ってちょっと便利な拡張機能を作ってみた / created-a-handy-extension-using-the-raycast-ai-api
kawamataryo
0
150
開発組織のための セキュアコーディング研修の始め方
flatt_security
3
2.7k
2.5Dモデルのすべて
yu4u
2
930
分解して理解する Aspire
nenonaninu
2
490
Iceberg Meetup Japan #1 : Iceberg and Databricks
databricksjapan
0
160
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
420
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.3k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
27
1.9k
The Invisible Side of Design
smashingmag
299
50k
Site-Speed That Sticks
csswizardry
4
390
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Done Done
chrislema
182
16k
Building Applications with DynamoDB
mza
93
6.2k
Raft: Consensus for Rubyists
vanstee
137
6.8k
Writing Fast Ruby
sferik
628
61k
Transcript
ා͘ͳ͍React @nokogiri ॳ৺ऀ͚React ϋϯζΦϯ
Nokogiri Job: SIer I — JS , Ruby ,Java and
Design. ͡Ί·ͯ͠
Nokogiri Job: SIer I — JS , Ruby ,Java and
Design. ͡Ί·ͯ͠ https://nokogiring.github.io/
ͱΓ͋͑ͣReactʹ৮ͬͯΈΔ ReactͷϝϦοτΛΔ ≠DOMૢ࡞ͳJSΛΔ ࠓΓ͍ͨ͜ͱ
ͱΓ͋͑ͣReactʹ৮ͬͯΈΔ ReactͷϝϦοτΛΔ ≠DOMૢ࡞ͳJSΛΔ ࠓΓ͍ͨ͜ͱ ͳΜ͔ͦ͠͏ͱࢥ͍ͬͯΔ ReactͷڪාΛऔΓআ͘
ࠓΒͳ͍͜ͱ ։ൃڥߏஙͷखॱ ES2015ͷઆ໌ ଞͷϥΠϒϥϦͱͷൺֱ jQueryσΟεΓ
What’s React ?
FacebookͷJavascriptϥΠϒϥϦ એݴతɾίϯϙʔωϯτࢦɾҰֶͿͱͲ͜Ͱ ͔͚Δ ʮԾDOMʯʹΑΔߴͳϨϯμϦϯά What’s React ?
FacebookͷJavascriptϥΠϒϥϦ એݴతɾίϯϙʔωϯτࢦɾҰֶͿͱͲ͜Ͱ ͔͚Δ ʮԾDOMʯʹΑΔߴͳϨϯμϦϯά ͱʹ͔͘ྲྀߦͬͯΔ What’s React ?
None
Hello World
// ҙͷϑΥϧμʹҠಈ cd Desktop // Ϋϩʔϯ git clone https://github.com/nokogiring/ReactLogoGenerator.git //
தʹҠಈ cd ReactLogoGenerator // ϞδϡʔϧͷΠϯετʔϧ npm i // Script࣮ߦ npm start Hello World https://github.com/nokogiring/ReactLogoGenerator
Hello World ϒϥβͰ http://localhost:3000 ʹΞΫηε
ղઆ
~লུ~ <body> <div id="root"></div> <script src="./dist/bundle.js"></script> </body> ~লུ~ Hello World
index.html
// ΤϯτϦʔϙΠϯτʹͳΔjs // React + ReactDomΛར༻͢Δ import React from 'react';
import ReactDom from 'react-dom'; // HTMLͷdomʹ།ҰΞΫηε͢ΔՕॴ const el = document.getElementById('root') // htmlͷ#rootʹ࡞͞ΕͨDomΛඳը͍ͯ͠Δ ReactDom.render( <div>Hello React World</div>, el ) Hello World src/index.js
// ΤϯτϦʔϙΠϯτʹͳΔjs // React + ReactDomΛར༻͢Δ import React from 'react';
import ReactDom from 'react-dom'; // HTMLͷdomʹ།ҰΞΫηε͢ΔՕॴ const el = document.getElementById('root') // htmlͷ#rootʹ࡞͞ΕͨDomΛඳը͍ͯ͠Δ ReactDom.render( <div>Hello React World</div>, el ) Hello World src/index.js จࣈΛม͑ͨΓɺଞͷλάʹஔ͖͑ͨΓͯ͠Έ·͠ΐ͏ɻ EJWλάͷதʹɺλάΛೖΕͯΈ·͠ΐ͏
σΟϨΫτϦߏͱਐΊํ
σΟϨΫτϦߏͱਐΊํ
σΟϨΫτϦߏͱਐΊํ ϑΥϧμ ࡞ۀ༻ϑΥϧμ ىͱͳΔ+4 Θ͔Βͳ͚ΕɺΛݟ͍ͯͩ͘͞ɻ
Hello World 2
ίϯϙʔωϯτࢦ
// ΤϯτϦʔϙΠϯτʹͳΔjs // React + ReactDomΛར༻͢Δ import React from 'react';
import ReactDom from 'react-dom'; // Hello WorldΛΠϯϙʔτ import HelloWorld from './HelloWorld/index'; // HTMLͷdomʹ།ҰΞΫηε͢ΔՕॴ const el = document.getElementById('root') // htmlͷ#rootʹ࡞͞ΕͨDomΛඳը͍ͯ͠Δ ReactDom.render( <HelloWorld />, el ) Hello World 2 src/index.js )FMMP8PSMEϞδϡʔϧͷ Πϯϙʔτ ඳը͢ΔରΛ )FMMP8PSMEʹมߋ
// ToDo // divλάʹ main ͱ͍͏ΫϥεΛՃ͠·͠ΐ͏ // h1ʹΠϯϥΠϯελΠϧͰ color :
tomato Λࢦఆ͠·͠ΐ͏ // JSXಛผͳϧʔϧ͕͋Δɻ // class => className // for => htmlFor // ΠϯϥΠϯελΠϧ style={{ xxxx: 'yyyyy' }} Ͱදݱ͠·͢ɻ <div> <h1>Hello World2</h1> </div> Hello World 2 src/HelloWorld/index.js
Hello World 2 ϒϥβJSΛߋ৽͢ΔͱࣗಈϦϩʔυ͠·͢ɻ ҎԼͷҎԼͷը໘͕ग़ΕOKͰ͢ɻ
ιʔεΛͬͯղઆ͠·͢ Hello World 2 src/HelloWorld/index.js
Page
// ΤϯτϦʔϙΠϯτʹͳΔjs // React + ReactDomΛར༻͢Δ import React from 'react';
import ReactDom from 'react-dom'; // PageΛΠϯϙʔτ import Page from './Page/index'; // HTMLͷdomʹ།ҰΞΫηε͢ΔՕॴ const el = document.getElementById('root') // htmlͷ#rootʹ࡞͞ΕͨDomΛඳը͍ͯ͠Δ ReactDom.render( <Page />, el ) Page src/index.js 1BHFϞδϡʔϧͷ Πϯϙʔτ ඳը͢ΔରΛ 1BHFʹมߋ
Page ൛͜Μͳײ͡
Page src/Page/index.js import React, { Component } from 'react'; //
Todo1 // Header,Sidebar,Main,footerͷindex.jsΛΠϯϙʔτ͍ͯͩ͘͠͞ɻ
Page src/Page/index.js // Todo2 // Header,Sidebar,Main,footerͷॱʹҎԼͷdivͷதʹίϯϙʔωϯτΛॻ͍͍ͯͩ͘͞ɻ // SidebarͱMainΛ"contents"ͱ͍͏ΫϥεͷdivλάͰғ͍ͬͯͩ͘͞ɻ <div> </div>
Page src/Sidebar/Page/index.js const contentsList = ["News", "Blog", "SNS", "Recruit", "aaa",
"bbb"]; let viewList = []; // Todo // contentsListͷཁૉ viewListʹ <Item /> Λ֨ೲ͍ͯͩ͘͠͞ɻ // ͜ͷͱ͖ <Item title={ contentsListͷཁૉ } key={ contentsListͷཁૉ } /> // ͱ͍͏ܗͰɺtitleͱkeyʹcontentsListͷཁૉΛࢦఆ͍ͯͩ͘͠͞ɻ // ͜Ε͕Կ͔࣍ͷষͰઆ໌͠·͢ɻ return ( <div className="sidebar"> {viewList} </div> );
JSϑΝΠϧΛׂ͢Δ͜ͱͰɺඞཁͳػೳຖʹϑΝ ΠϧΛׂͰ͖ΔΠϝʔδ͕Ͱ͖ͨͣ ֎ଆ͔Βύϥϝʔλͱͯ͢͜͠ͱ͕Ͱ͖Δ HTMLͱJS͕ີ݁߹ Page
Props & State
Props & State ࣮ԋ
// ΤϯτϦʔϙΠϯτʹͳΔjs // React + ReactDomΛར༻͢Δ import React from 'react';
import ReactDom from 'react-dom'; // PropsStateΛΠϯϙʔτ import PropsState from './PropsState/index'; // HTMLͷdomʹ།ҰΞΫηε͢ΔՕॴ const el = document.getElementById('root') // htmlͷ#rootʹ࡞͞ΕͨDomΛඳը͍ͯ͠Δ ReactDom.render( <PropsState defaultValue="Mastodon" />, el ) Props & State src/index.js 1SPQT4UBUFϞδϡʔϧͷ Πϯϙʔτ ඳը͢ΔରΛ 1SPQT4UBUFʹมߋ EFGBVMU7BMVFΛઃఆ
Props & State src/PropsState/index.js // Todo1 // textarea ͷ style
ʹ textAreaStyle ΛదԠ͍ͤͯͩ͘͞͞ɻ // textarea ͷ value ʹ this.state.text ΛదԠ͍ͤͯͩ͘͞͞ɻ // textarea ͷ onChange ʹ this._setValue ΛదԠ͍ͤͯͩ͘͞͞ɻ // Todo2 // "จࣈɿ" ͷޙΖʹ this.state.count Λग़ྗ͍ͯͩ͘͠͞ɻ // "resultɿ" ͷޙΖʹ this.state.text Λग़ྗ͍ͯͩ͘͠͞ɻ return ( <div className="main"> <h1>Props State Counter</h1> <input type="textarea" /> <span> จࣈ : </span> <p>result: </p> </div> );
Props & State src/PropsState/index.js constructor(props) { super(props); this.state = {
// Todo3 // textͷΛ "" => this.props.defaultValue ʹมߋ͍ͯͩ͘͠͞ɻ // countͷΛ 0 =>ɹthis.props.defaultValue.length ʹมߋ͍ͯͩ͘͠͞ɻ text: "", count: 0, } this._setValue = this._setValue.bind(this); }
Props & State src/PropsState/index.js // Πϕϯτϋϯυϥʔ // ೖྗϑΟʔϧυͷΛstateʹઃఆ͢Δ _setValue(e) {
// Todo4 // text, countʹ textarea ͷೖྗจࣈྻͱ count ͷೖྗจࣈྻΛೖΕ͍ͯͩ͘͞ɻ // textareaͷೖྗจࣈྻ e.target.value // textareaͷೖྗจࣈྻ e.target.value.length // ͰऔಘͰ͖·͢ɻ this.setState({ text: "", count: 0, }) }
ιʔεΛͬͯղઆ͠·͢ Props & State src/PropsState/index.js
Props => ֎෦͔Β͞ΕΔ Πϛϡʔλϒϧ(ޙͰมߋෆՄೳ) State => ίϯϙʔωϯτ෦Ͱཧ͢Δ ϛϡʔλϒϧ(ޙͰมߋՄೳ) Props &
State
PropsΛΠϯϙʔτ࣌ʹ͢͜ͱͰίϯϙʔωϯτ ͷதͰར༻Ͱ͖·͢ɻ React͕Stateͷͷมߋʹै͍ɺมߋલޙͷࠩ ͚ͩΛ࠶ඳը͍ͯ͠·͢ɻ Props & State
ReactDom.render( <div> <PropsState defaultValue="Mastodon" />, <PropsState defaultValue="Twitter" />, </div>, el
) Props & State src/index.js EJWͰғͬͯɺ 1SPQT4UBUFΛ̎ͭ͏ EFGBVMU7BMVFΛมߋͯ͠ΈΔ
LogoGenerator
ίϯϙʔωϯτΛ·͕ͨͬͯ εςʔτΛड͚͢
LogoGenerator ࣮ԋ
// ΤϯτϦʔϙΠϯτʹͳΔjs // React + ReactDomΛར༻͢Δ import React from 'react';
import ReactDom from 'react-dom'; // ίϯϙʔωϯτΛΠϯϙʔτ import LogoGenerator from './LogoGenerator/index' // HTMLͷdomʹ།ҰΞΫηε͢ΔՕॴ const el = document.getElementById('root') // htmlͷ#rootʹ࡞͞ΕͨDomΛඳը͍ͯ͠Δ ReactDom.render( <div> <LogoGenerator /> </div>, el ) LogoGenerator src/index.js 1SPQT4UBUFϞδϡʔϧͷ Πϯϙʔτ ඳը͢ΔରΛ -PHP(FOFSBUPSʹมߋ
LogoGenerator src/LogoGenerator/index.js // Todo1 // logo ͷதͷ <Message></Message>ίϯϙʔωϯτʹҎԼͷϓϩύςΟʹཧ͍ͯ͠Δ // ಉ໊ͷStateΛηοτ͍ͯͩ͘͠͞ɻ(ώϯτ
hogehoge={this.state.hogehoge}) // backgroundColor // fontSize // fontfamily // textColor // Todo2 // <Message></Message>ίϯϙʔωϯτͷࢠͲͱͯ͠ // StateͰཧ͍ͯ͠Δ textValue ΛೖΕ͍ͯͩ͘͞ɻ // ࢠͲ(fugafuga)ʹड͚͢ํ๏<hogehoge>{this.state.fugafuga}</hogehoge> // hogehogeΫϥε this.props.children ͰfugafugaΛड͚औΓ·͢ɻ // ϩΰ const logo = ( <Message> </Message> )
LogoGenerator src/LogoGenerator/index.js Todo3 <Button>ίϯϙʔωϯτΛͬͯɺϩΰΛ০͢ΔϘλϯΛ࡞͍ͯͩ͘͠͞ɻ {/*Todo3ɹPlease fill me !*/} ͱ͍͏ՕॴΛ͏Ί͍ͯͩ͘͞ɻ <Button>ίϯϙʔωϯτʹɺname,
selectedName, handleClickΛϓϩύςΟͱ͍ͯͯͩ͘͠͠͞ɻ FontFamilyϘλϯͷ name names_FontFamily ͔Βऔಘ໊ͨ͠લΛઃఆ͍ͯͩ͘͠͞ɻ FontFamilyϘλϯͷ selectedName stateͷ fontfamily Λઃఆ͍ͯͩ͘͠͞ɻ FontFamilyϘλϯͷ handleClick this._selectFontFamily ͔Βऔಘ͍ͯͩ͘͠͞ɻ TextColorϘλϯͷ name names_textColor ͔Βऔಘ໊ͨ͠લΛઃఆ͍ͯͩ͘͠͞ɻ TextColorϘλϯͷ selectedName stateͷtextColor Λઃఆ͍ͯͩ͘͠͞ɻ TextColorϘλϯͷ handleClick this._selectTextColor ͔Βऔಘ͍ͯͩ͘͠͞ɻ BackGroundColorϘλϯͷ name names_FontFamily ͔Βऔಘ໊ͨ͠લΛઃఆ͍ͯͩ͘͠͞ɻ BackGroundColorϘλϯͷ selectedName stateͷ fontfamily Λઃఆ͍ͯͩ͘͠͞ɻ BackGroundColorϘλϯͷ handleClick this._selectBackGroundColor ͔Βऔಘ͍ͯͩ͘͠͞ɻ
ιʔεΛͬͯղઆ͠·͢ Props & State src/PropsState/index.js
ؔΛίϯϙʔωϯτʹpropsͱͯ͢͜͠ͱ͕Ͱ ͖·͢ɻstateͷཧ͕͍࣋ͬͯΔͷͰɺͷ stateΛߋ৽͢ΔؔΛࢠͲʹ͢͜ͱͰɺ͜Ͳ ͕ͷstateΛߋ৽Ͱ͖·͢ɻ LogoGenerator
͝੩ௌ͋Γ͕ͱ͏ ͍͟͝·͍ͨ͠