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

初めてのReact

Kono Junya
August 04, 2017

 初めてのReact

React.jsを初めて勉強する人向けのスライドです!

Kono Junya

August 04, 2017
Tweet

More Decks by Kono Junya

Other Decks in Technology

Transcript

  1. src/app.js import React from “react”; import { render } from

    “react-dom”; // componentΛimport͢Δ import Hello from “./components/Hello.jsx”; render( <Hello/>, document.getElementById(“app”) );
  2. src/components/Hello.jsx import React from “react”; const style = { color:

    “red” } const Hello = () => ( <h1 style={style}>Hello World</h1> ) export default Hello;
  3. src/components/Hello.jsx import React from “react”; const Hello = () =>

    ( <h1 className=“red”>Hello World</h1> ) export default Hello;
  4. src/components/Hello.jsx import React from “react”; const Hello = ({ color

    }) => ( <h1 style={{ color }}>Hello World</h1> ) export default Hello;
  5. src/components/App.jsx import React from “react”; import Hello from “./Hello.jsx” const

    App = () => ( <div> <Hello color=“red” /> </div> ) export default App;
  6. src/app.js import React from “react”; import { render } from

    “react-dom”; // componentΛimport͢Δ import App from “./components/App.jsx”; render( <App/>, document.getElementById(“app”) );
  7. src/components/App.jsx import React from “react”; import Hello from “./Hello.jsx” const

    colors = [“red”,”blue”] const App = () => ( <div> { colors.map(color => ( <Hello color={color} /> )) } </div> ) export default App;
  8. src/components/App.jsx import React from “react”; import Hello from “./Hello.jsx” const

    items = [ { id: 1, color: “red” }, { id: 2, color: “blue” } ] const App = () => ( <div> { items.map(item => { <Hello color={item.color} key={item.id} /> }) } </div> ) export default App;
  9. src/components/ MyButton.jsx import React from “react”; const MyButton = ()

    => ( <button onClick={() => alert(“ϙνʙ”)}>push me!</button> ) export default MyButton;
  10. src/components/ MyButton.jsx import React from “react”; export default class MyButton

    extends React.Component { render(){ return( <button onClick={this.onClickHandler}>push me!</button> ) } onClickHandler(){ let pochi = “ϙνʙ”; alert(pochi); } }
  11. src/components/MyInput.jsx import React from “react”; export default class MyInput extends

    React.Component { render(){ return( <div> <input/> </div> ) } }
  12. src/components/MyInput.jsx import React from “react”; import MyButton from “./MyButton.jsx” export

    default class MyInput extends React.Component { render(){ return( <div> <input/> <MyButton onClick={this.onClickHandler}/> </div> ) } onClickHandler(){ alert(“ϙνʙ”) } }
  13. src/components/ MyButton.jsx import React from “react”; export default class MyButton

    extends React.Component { constructor(props){ super(props) } render(){ return( <button onClick={this.props.onClick}>push me!</button> ) } }
  14. import React from “react”; import MyButton from “./MyButton.jsx” export default

    class MyInput extends React.Component { constructor(){ super() this.state = { value: “” } } render(){ return( <div> <input value={this.state.value} onChange={this.setTextData} /> <MyButton onClick={this.onClickHandler}/> </div> ) } setTextData(e){ let text = e.target.value this.setState({ value: text }) } onClickHandler(){ alert(“ϙνʙ”) } }