React

Best practices for React JS developer part-2

Best practices for React JS developer part-2

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

				
					<Home
  UserName="demo"
  phone_number={9898989898}
/>
				
			

Good

				
					<Home
  userName="demo"
  phoneNumber={9898989898}
/>
				
			

Tags close it self

Any component in not use children so closing it self

Not Good

				
					<Home userName="demo"></Home>
				
			

Good

				
					<Home
  userName="demo"
/>
				
			

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

				
					<img decoding="async" src="hello.png" />
				
			

Good

				
					<img decoding="async" src="hello.png" alt="This is hero image" />
				
			
Share On: