During the Passing Thought Project Passing Thought - Front-end Developer - React
step 8 asks to submit only if the user types in the input form… Well, It is just a matter of enveloping the handlesubmit body in an if statemente for the lenght of text… but after I do this it no longer submits anything. Removing the if statement restores the submit ability…
import React, { useState } from 'react';
import { generateId, getNewExpirationTime } from './utilities';
export function AddThoughtForm(props) {
const [ text, setText] = useState('');
const handleTextChange = (event) => {
setText(event.target.value)
};
const handleSubmit = (event) => {
if (text.lenght > 0) {
event.preventDefault();
const newThought = {
id: generateId(),
text: text,
expiresAt: getNewExpirationTime(),
};
props.addThought(newThought);
setText('');
};
};
return (
<form onSubmit={handleSubmit} className="AddThoughtForm">
<input
value={text}
onChange={handleTextChange}
type="text"
aria-label="What's on your mind?"
placeholder="What's on your mind?"
/>
<input type="submit" value="Add" />
</form>
);
}