-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseInput.js
More file actions
44 lines (36 loc) · 1021 Bytes
/
CourseInput.js
File metadata and controls
44 lines (36 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import React, { useState } from 'react';
import Button from '../../UI/Button/Button';
import styles from './CourseInput.module.css';
const CourseInput = props => {
const [enteredValue, setEnteredValue] = useState('');
const [isValid,setIsValid] =useState(true)
const goalInputChangeHandler = event => {
if(event.target.value.trim().length>0){
setIsValid(true)
return
}
setEnteredValue(event.target.value);
};
const formSubmitHandler = event => {
event.preventDefault();
if(enteredValue.trim().length===0){
setIsValid(false)
return
}
props.onAddGoal(enteredValue);
};
return (
<form onSubmit={formSubmitHandler}>
<div className={`${styles["form-control"]} ${!isValid && styles.invalid}`}>
<label>Course Goal
</label>
<input
type="text"
onChange={goalInputChangeHandler} />
</div>
<Button
type="submit">Add Goal</Button>
</form>
);
};
export default CourseInput;