|
17 | 17 | //////////////////////////////////////////////////////////////////////////////// |
18 | 18 | import React from "react"; |
19 | 19 | import ReactDOM from "react-dom"; |
20 | | -import PropTypes from "prop-types"; |
21 | 20 |
|
22 | | -class Form extends React.Component { |
23 | | - render() { |
24 | | - return <div>{this.props.children}</div>; |
25 | | - } |
| 21 | +function Form({ children }) { |
| 22 | + return <div>{children}</div>; |
26 | 23 | } |
27 | 24 |
|
28 | | -class SubmitButton extends React.Component { |
29 | | - render() { |
30 | | - return <button>{this.props.children}</button>; |
31 | | - } |
| 25 | +function SubmitButton({ children }) { |
| 26 | + return <button>{children}</button>; |
32 | 27 | } |
33 | 28 |
|
34 | | -class TextInput extends React.Component { |
35 | | - render() { |
36 | | - return ( |
37 | | - <input |
38 | | - type="text" |
39 | | - name={this.props.name} |
40 | | - placeholder={this.props.placeholder} |
41 | | - /> |
42 | | - ); |
43 | | - } |
| 29 | +function TextInput({ name, placeholder }) { |
| 30 | + return <input type="text" name={name} placeholder={placeholder} />; |
44 | 31 | } |
45 | 32 |
|
46 | | -class App extends React.Component { |
47 | | - handleSubmit = () => { |
| 33 | +function App() { |
| 34 | + function handleSubmit() { |
48 | 35 | alert("YOU WIN!"); |
49 | | - }; |
| 36 | + } |
50 | 37 |
|
51 | | - render() { |
52 | | - return ( |
53 | | - <div> |
54 | | - <h1> |
55 | | - This isn't even my final <code><Form/></code>! |
56 | | - </h1> |
| 38 | + return ( |
| 39 | + <div> |
| 40 | + <h1> |
| 41 | + This isn't even my final <code><Form/></code>! |
| 42 | + </h1> |
57 | 43 |
|
58 | | - <Form onSubmit={this.handleSubmit}> |
59 | | - <p> |
60 | | - <TextInput name="firstName" placeholder="First Name" />{" "} |
61 | | - <TextInput name="lastName" placeholder="Last Name" /> |
62 | | - </p> |
63 | | - <p> |
64 | | - <SubmitButton>Submit</SubmitButton> |
65 | | - </p> |
66 | | - </Form> |
67 | | - </div> |
68 | | - ); |
69 | | - } |
| 44 | + <Form onSubmit={handleSubmit}> |
| 45 | + <p> |
| 46 | + <TextInput name="firstName" placeholder="First Name" />{" "} |
| 47 | + <TextInput name="lastName" placeholder="Last Name" /> |
| 48 | + </p> |
| 49 | + <p> |
| 50 | + <SubmitButton>Submit</SubmitButton> |
| 51 | + </p> |
| 52 | + </Form> |
| 53 | + </div> |
| 54 | + ); |
70 | 55 | } |
71 | 56 |
|
72 | 57 | ReactDOM.render(<App />, document.getElementById("app")); |
0 commit comments