Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

ReactJS stateless component parameter

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 7 months 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}) => {}

usr_profile.png

User

( 7 months 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

usr_profile.png

User

( 7 months 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

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif