Skip to content

Commit e86228e

Browse files
committed
Make SignUp a controlled component
1 parent d6e60c7 commit e86228e

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/components/SignUp/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const SignUp = ({ handleChange, handleSubmit, error }) => {
4+
const SignUp = ({
5+
firstName,
6+
lastName,
7+
email,
8+
password,
9+
handleChange,
10+
handleSubmit,
11+
error
12+
}) => {
513
return (
614
<div>
715
<form onSubmit={handleSubmit}>
@@ -11,27 +19,31 @@ const SignUp = ({ handleChange, handleSubmit, error }) => {
1119
type="text"
1220
name="firstName"
1321
placeholder="First Name"
22+
value={firstName}
1423
onChange={handleChange}
1524
/>
1625
<br />
1726
<input
1827
type="text"
1928
name="lastName"
2029
placeholder="Last Name"
30+
value={lastName}
2131
onChange={handleChange}
2232
/>
2333
<br />
2434
<input
2535
type="email"
2636
name="email"
2737
placeholder="Email"
38+
value={email}
2839
onChange={handleChange}
2940
/>
3041
<br />
3142
<input
3243
type="password"
3344
name="password"
3445
placeholder="Password"
46+
value={password}
3547
onChange={handleChange}
3648
/>
3749
<br />
@@ -42,9 +54,13 @@ const SignUp = ({ handleChange, handleSubmit, error }) => {
4254
};
4355

4456
SignUp.propTypes = {
57+
firstName: PropTypes.string.isRequired,
58+
lastName: PropTypes.string.isRequired,
59+
email: PropTypes.string.isRequired,
60+
password: PropTypes.string.isRequired,
4561
handleChange: PropTypes.func.isRequired,
4662
handleSubmit: PropTypes.func.isRequired,
47-
error: PropTypes.string.isRequired
63+
error: PropTypes.string
4864
};
4965

5066
export default SignUp;

src/containers/SignUpContainer/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SignUpContainer extends Component {
1212
lastName: '',
1313
email: '',
1414
password: '',
15-
error: ''
15+
error: null
1616
};
1717

1818
handleChange = e => {
@@ -53,11 +53,17 @@ class SignUpContainer extends Component {
5353
};
5454

5555
render() {
56+
const { firstName, lastName, email, password, error } = this.state;
57+
5658
return (
5759
<SignUp
60+
firstName={firstName}
61+
lastName={lastName}
62+
email={email}
63+
password={password}
5864
handleChange={this.handleChange}
5965
handleSubmit={this.handleSubmit}
60-
error={this.state.error}
66+
error={error}
6167
/>
6268
);
6369
}

0 commit comments

Comments
 (0)