Today we are going to see best practices for React JS developer
- Passing a boolean variables.
- Do not define a function within a render
- Naming of the components
- Use of the Ternary Operators
- Don’t Need Curly Braces in string
Passing a boolean variables
Passing boolean variables in to two components.
Not Good
return (
);
Good
return (
);
Do not define a function within a render
Don’t define a function inside render.
Not Good
return (
)
Good
const submitData = () => dispatch(ACTION_TO_SEND_DATA)
return (
)
Naming of the components
You can use PascalCase for name of the components and camelCase for name of the instances.
Not Good
import createCard from './CreateCard';
const ReservationItem = ;
Good
import CreateCard from './CreateCard';
const reservationItem = ;
Use of the Ternary Operators
Developer how can use ternary operator in React js.
Not Good
const { role } = user;
if(role === 'ADMIN') {
return
}else{
return
}
Good
const { role } = user;
return role === 'ADMIN' ? :
Don’t Need Curly Braces in string
When developer passing string props to a children component
Not Good
return(
)
Good
return(
)
Hope this helps for React js developer