Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need more clarity about react props #12

Open
smcalilly opened this issue Mar 17, 2021 · 1 comment
Open

need more clarity about react props #12

smcalilly opened this issue Mar 17, 2021 · 1 comment

Comments

@smcalilly
Copy link
Owner

Is props just the name of an object like cat, but just a name that React chooses to use? What is more common in React apps? To see props.name or to just destructure the object so you don't even see props. Is there any reason why I need to use props in my react app? Or could I just get the data (from a CMS graphql query for instance) and put it into an object with any name (like cat) or just skip the naming part and destructure it directly? Or is there a good reason to use props with React?

Need more clarity on the React concept of props. I do think it's good to introduce here because that is what you're gonna see a ton of when you start googling code examples, but some more explanation is needed.

@smcalilly
Copy link
Owner Author

Is props just the name of an object like cat, but just a name that React chooses to use?

yes

What is more common in React apps? To see props.name or to just destructure the object so you don't even see props.

I like destructuring because it's cleaner.

Is there any reason why I need to use props in my react app?

No, not if you destructure your objects correctly.

Or could I just get the data (from a CMS graphql query for instance) and put it into an object with any name (like cat) or just skip the naming part and destructure it directly? Or is there a good reason to use props with React?

Yes, this is exactly the way. I'll add this to the opinion section. I suppose that's a personal preference thing. Would be cool to somehow incorporate a poll or analysis react code to see if props is used more or less. The argument could be made that it gives a code reader an easy way to grasp that props.name is coming from a parent component. On the other side, it's cleaner when you're just passing name into the component with destructuring, but you don't have that quick cue of props to indicate the data is "passed in via props". So not using props might make a code reader think more, but if your components are small and not too many lines of code (and thus easier to think about), then not using props would be appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant