Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React by Example Building the Application Adding Guests to the List

Sam Gord
Sam Gord
14,060 Points

is adding unnecessary components harmful?

for connecting the value of input to the pendingGuest state i made a new component for the input that adds new name and did all the same from there , the only change was the value of input which i used props.children as below-->

import React from 'react';
import PropTypes from 'prop-types';

const Addname = props =>
    <input type="text" value={props.children} placeholder="Invite Someone" onChange={props.pendingName} />

Addname.propTypes = {
    pendingName: PropTypes.func.isRequired,
}

export default Addname;

so my question is that did i do something wrong by making an unnecessary component or not? thanks

1 Answer

jared eiseman
jared eiseman
29,023 Points

I wouldn't say you did anything wrong per se. The "rule", if you can call it that, really is just make new components when it makes sense. Whether that be a readability thing or a reusability thing. Generally speaking, it won't affect performance in any meaningful way. If it makes more sense, and/or that component can be used elsewhere, A++.

if (reusable || readable) {
  makeNewComponent();
} else {
  whatevs();
}