-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implented #918
base: master
Are you sure you want to change the base?
implented #918
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compare your implementation with working example
do not show right side bar when no selected any post
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, lets improve your code a bit. Also ypu could check similar case on other places
src/components/NewCommentForm.tsx
Outdated
const [name, setName] = useState(''); | ||
const [isNameError, setIsNameError] = useState(false); | ||
const [email, setEmail] = useState(''); | ||
const [isEmailError, setIsEmailError] = useState(false); | ||
const [body, setBody] = useState(''); | ||
const [isBodyError, setIsBodyError] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption it's better to have 2 states instead of 6. One for fields
const [form, setForm] = useState({
name: '',
....
});
second for error message< by default it's empty string
const [errorMsg, setErrorMsg] = useState('');
src/components/NewCommentForm.tsx
Outdated
onChange={(e) => { | ||
setName(e.target.value); | ||
setIsNameError(false); | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use anonymous function use separate handler
It will works for all fields
const onFieldChange = ({taget: {value, name}}) => {
setForm(prevState => {...prevState, [name]: value })
}
https://ZadorozhnyiYevhenii.github.io/react_dynamic-list-of-posts/