ReactJS stateless component parameter

General Tech Bugs & Fixes 2 years ago

0 3 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (3)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

What is the preferred/correct choice for ReactJS stateless component's parameter? Is it props or list out all prop names?

Choice 1:

const Checkbox = props => {}

Choice 2:

const Checkbox = ({name, value}) => {}
profilepic.png
manpreet 2 years ago

There is not incorrect choice here.

If you have a few props only, like in your example name and value you can destructure them. If you have 10+ props, I think it's better to use just props and then work with them in the component body, just because of the visual style


0 views   0 shares

profilepic.png
manpreet 2 years ago

Way way you want to use you component depends on how your component is implemented and its a matter of personal preference as well. The functional component is passed as props as argument post which you may prefer to use it as it is or destructure it

Choice 1: const Checkbox = props => {}

Most often you may use the above method when there are too many props that you wish to use or pass all of them down to the child component

Choice 2: const Checkbox = ({name, value}) => {}

The above pattern is where you destructure name and value from props. You may choose to do so when you only need to use name and value out of all the props passed


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.