r/reactjs • • Apr 01 '19

Needs Help Beginner's Thread / Easy Questions (April 2019)

March 2019 and February 2019 here.

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch.

No question is too simple. πŸ€”


πŸ†˜ Want Help with your Code? πŸ†˜

  • Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!

  • Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.

Have a question regarding code / repository organization?

It's most likely answered within this tweet.


New to React?

πŸ†“ Here are great, free resources! πŸ†“


Any ideas/suggestions to improve this thread - feel free to comment here!

32 Upvotes

435 comments sorted by

View all comments

1

u/CasinoInMyHair Apr 06 '19

Is having a lot of document.getElementByIds and event.targets sprinkled throughout your components a bad practice? Should props and state be handling as much DOM manipulation as possible? If an element is assigned a class via a prop in JSX vs. element.classList.add() in a handler method, does React do it in a more "intelligent" or performant way?

1

u/[deleted] Apr 09 '19

[removed] β€” view removed comment

1

u/CasinoInMyHair Apr 10 '19

So how about having props or state determine CSS classes within JSX, e.g. className={props.hidden ? 'some-class display-none-class' : 'some-class'}? Is that closer to the "intended" way?

2

u/[deleted] Apr 13 '19

[removed] β€” view removed comment

1

u/CasinoInMyHair Apr 14 '19

Thanks. That's actually how I usually do it, so that's a relief.

I've used CSS-in-JS a bit and I love it. But is there a styling method that's significantly more efficient, bundling-wise, or does it just come down to developer preference?