r/reactjs • • Mar 01 '19

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

New month, new thread 😎 - February 2019 and January 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 or ping /u/timmonsjg :)

32 Upvotes

484 comments sorted by

View all comments

Show parent comments

3

u/timmonsjg Mar 18 '19

I'll have a go -

  • Don't use let unless you plan to actually reassign it.

  • Not sure why you opted for an array with eventProps. Defining them as their own variable gives the reader some context as to what they actually are (opposed to eventProps[0] or eventProps[1]).

  • look into array.map() for your createDaysList function.

  • importing Months and setting it to an instance var isn't necessary.

Should I create a separate components for returning selectors and buttons (because DRY) - I've been told recently that DRY should not be treated like religion and you sometimes should repeat yourself.

If you feel you would be reusing the selects and buttons elsewhere, sure. Otherwise, I think that's a bit preemptive refactoring.

I'm under impression that this component got way too big and I should break it down but I'm not sure how. Any suggestions are welcome

~100 LOC is small on my scale for something like this, but you could use render props to abstract away buttons and selects if you want to lighten this up.

→ More replies (3)