In the previous article, we learned 5 areas or tips on Best practices for React JS developer.
In this article, we will learn more about areas or tips
6. Object Destructuring.
7. When pass value in props
8. Tags close it self.
9. Do not use underscore in any method name.
10. Use alt in img tag.
Object distracting
You can use object distracting
Not Good
return (
<>
{user.firstName}
>
)
Good
const { firstName } = user;
return (
<>
{firstName}
>
)
When pass value in props
When pass the data between two component that time use camelCase for prop names.
Not Good
Good
Tags close it self
Any component in not use children so closing it self
Not Good
Good
Do not use underscore in any method name
You don’t need underscores in any React method.
Not Good
const _onClickHandler = () => {
// Your code
}
Good
const onClickHandler = () => {
// Your code
}
Use alt attribute in img tag
Do use alt attribute in the img tag. and don’t use picture or image name in your alt property.
Not Good
Good