Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSam Gord
14,084 Pointsis 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
29,023 PointsI 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();
}