Commit 4fffcd8d by Moorthy G

add proptypes to todoform

parent 8e390a37
import React, { useState } from "react"; import PropTypes from 'prop-types';
import React, { useState } from 'react';
function TodoForm(props) { function TodoForm(props) {
const [input, setInput] = useState('');
const [input, setInput] = useState("");
const onChange = (e) => { const onChange = (e) => {
setInput(e.target.value); setInput(e.target.value);
...@@ -10,31 +10,34 @@ function TodoForm(props) { ...@@ -10,31 +10,34 @@ function TodoForm(props) {
const Submit = (e) => { const Submit = (e) => {
e.preventDefault(); e.preventDefault();
props.onSubmit({ props.onSubmit({
id: Math.floor(Math.random() * 10000), id: Math.floor(Math.random() * 10000),
text: input, text: input,
status: false status: false,
}); });
setInput(""); setInput('');
}; };
return ( return (
<> <form onSubmit={Submit}>
<form onSubmit={Submit}> <div className='add-form'>
<div className="add-form"> <div className='form-control'>
<div className='form-control'> <input
<input placeholder='Enter Item'
placeholder="Enter Item" value={input}
value={input} onChange={onChange}
onChange={onChange} name='text'
name="text" /> />
</div>
<button className="btn" onClick={Submit}>Submit</button>
</div> </div>
</form> <button className='btn' onClick={Submit}>
</> Submit
</button>
</div>
</form>
); );
} }
export default TodoForm; export default TodoForm;
TodoForm.propTypes = {
onSubmit: PropTypes.func,
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment