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

[Mix Leap] Reactを実案件で使って思った''成功''と''反省''

k.maeda
January 12, 2018

[Mix Leap] Reactを実案件で使って思った''成功''と''反省''

2018年 1月 11日のMixLeapで利用したスライドです。

k.maeda

January 12, 2018
Tweet

Other Decks in Programming

Transcript

  1. Who am I ? • Name: Keisuke Maeda • Age:

    22 • Programming: ◦ JavaScript (React, Angular) ◦ Python ◦ PHP ◦ Ruby
  2. ࣮ྫ঺հ ࣮ྫᶃ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # !"" containers # !"" index.jsx # !"" reducers # !"" route.jsx # !"" settings # !"" stylesheets # $"" utils σΟϨΫτϦߏ੒
  3. ࣮ྫ঺հ ࣮ྫᶃ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # !"" containers # !"" index.jsx # !"" reducers # !"" route.jsx # !"" settings # !"" stylesheets # $"" utils ← Actions ← Containers ← Reducers Reduxͷߏ੒෦඼
  4. ࣮ྫ঺հ ࣮ྫᶃ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # !"" containers # !"" index.jsx # !"" reducers # !"" route.jsx # !"" settings # !"" stylesheets # $"" utils ← ڞ௨Components ΞϓϦέʔγϣϯͷߏ੒෦඼ ← ֤ϖʔδ ← ΞϓϦέʔγϣϯͷϧʔτ ←ϧʔςΟϯά
  5. ࣮ྫ঺հ ࣮ྫᶃ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # !"" containers # !"" index.jsx # !"" reducers # !"" route.jsx # !"" settings # !"" stylesheets # $"" utils ← ΞϓϦͷઃఆϑΝΠϧ ͦͷଞ ← cssϑΥϧμ ← ൚༻తؔ਺ϑΥϧμ
  6. ࣮ྫ঺հ ࣮ྫᶄ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # # !"" Routes # !"" config # !"" containers # !"" index.js # !"" models # !"" reducers # !"" styles # $"" utils σΟϨΫτϦߏ੒
  7. ࣮ྫ঺հ ࣮ྫᶄ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # # !"" Routes # !"" config # !"" containers # !"" index.js # !"" models # !"" reducers # !"" styles # $"" utils ← Actions ( Redux Actions ) ← Containers ← Reducers Reduxͷߏ੒෦඼ ← Model ( Immutable.js )
  8. ࣮ྫ঺հ ࣮ྫᶄ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # # !"" Routes # !"" config # !"" containers # !"" index.js # !"" models # !"" reducers # !"" styles # $"" utils ← ڞ௨Components ΞϓϦέʔγϣϯͷߏ੒෦඼ ← ֤ϖʔδ ← ΞϓϦέʔγϣϯͷϧʔτ ←ϧʔςΟϯά
  9. ࣮ྫ঺հ ࣮ྫᶄ ʙߏ੒ʙ !"" src # !"" actions # !""

    components # # !"" Common # # !"" Routes # !"" config # !"" containers # !"" index.js # !"" models # !"" reducers # !"" styles # $"" utils ← ΞϓϦͷઃఆϑΝΠϧ ͦͷଞ ← cssϑΥϧμ ← ൚༻తؔ਺ϑΥϧμ
  10. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ <Recharts /> const data = [ {name: 'Data A',

    value: 4000}, {name: 'Data B', value: 3000}, {name: 'Data C', value: 2000}, {name: 'Data D', value: 2780}, {name: 'Data E', value: 1890}, {name: 'Data F', value: 2390}, {name: ‘Data G', value: 3490}, ] ද͍ࣔͤͨ͞σʔλ render () { return ( <LineChart width={400} height={400} data={data}> <Line type="monotone" dataKey=“value” /> </LineChart> ) } Renderʹ௥Ճ
  11. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ Reapop notify({ title: 'Welcome', message: ‘Hello!!’, status: 'success', dismissible:

    true, dismissAfter: 3000 }); render() { return ( <div> <NotificationsSystem theme={theme}/> </div> ); } ↓ݺͼग़͢͜ͱͰ௨஌͕දࣔ͞ΕΔ→ ←௥Ճ(ද্ࣔมԽ͸ͳ͍)
  12. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ Redux FormΛಋೖ͢Δͱ… ᶄ Redux FormఏڙͷComponentʹΑΓɺ ϑΥʔϜͷ࡞੒ɺόϦσʔγϣϯͳͲָ͕ʹͳΔɻ export default reduxForm({

    form: 'SubmitForm', // Formͷ໊শ(ΞϓϦ಺ͰҰҙ) validate, // ͜ͷϑΥʔϜͰར༻͢ΔόϦσʔγϣϯ })(SubmitForm) reduxForm Component FormͷΦϓγϣϯ(໊લɺόϦσʔγϣϯͳͲ)
  13. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ Redux FormΛಋೖ͢Δͱ… Validation <form onSubmit={handleSubmit}> <Field name="username" type="text" component=“input"

    label="Username" /> <div> <button type="submit"> Submit </button> </div> </form> const validate = values => { const errors = {} if (!values.username) { errors.username = 'Required' } else if (values.username.length > 15) { errors.username = 'Must be 15 characters or less' } return errors } export default reduxForm({ form: 'SubmitForm', // Formͷ໊শ(ΞϓϦ಺ͰҰҙ) validate, // ͜ͷϑΥʔϜͰར༻͢ΔόϦσʔγϣϯ })(SubmitForm) Submit࣌ʹvalidate͕ݺ͹ΕΔ • valuesʹ͸Formͷ஋͕དྷΔ Form
  14. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ Redux FormΛಋೖ͢Δͱ… Validation const validate = values => {

    const errors = {} if (!values.username) { errors.username = 'Required' } else if (values.username.length > 15) { errors.username = 'Must be 15 characters or less' } return errors } Result <Field />Ͱғ͍ͬͯΔ͜ͱͰɺରԠ߲ͨ͠໨ʹ ࣗಈతʹΤϥʔϝοηʔδ͕දࣔ͞ΕΔɻ
  15. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ react-bootstrap-table render() { return ( <BootstrapTable data={ products }>

    <TableHeaderColumn dataField='id' isKey>Product ID</TableHeaderColumn> <TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn> <TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn> </BootstrapTable> ); }
  16. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ react-bootstrap-table products = [ { id: 1, name: “Item

    name 0”, price: 2100 },… ]; <BootstrapTable data={ products }> <TableHeaderColumn dataField=‘id’ isKey > Product ID </TableHeaderColumn> <TableHeaderColumn dataField=‘name' > Product Name </TableHeaderColumn> <TableHeaderColumn dataField=‘price' > Product Price </TableHeaderColumn> </BootstrapTable> <TableHeaderColumn />ͷதʹɺ ɹɹɹɹͦͷྻͰද͍ࣔͨ͠ϓϩύςΟΛࢦఆ(dataField)
  17. ར༻͍ͯ͠ΔओͳϥΠϒϥϦ react-bootstrap-table <TableHeaderColumn dataField=“id” dataSort > Product ID </TableHeaderColumn> ιʔτ

    Customize(Ұ෦) <BootstrapTable data={products} pagination > … </BootstrapTable> ϖʔδωʔτ