r/reactjs • • Jul 01 '18

Help Beginner's Thread / Easy Question (July 2018)

Hello! just helping out /u/acemarke to post a beginner's thread for July! we had almost 550 Q's and A's in last month's thread! That's 100% month on month growth! we should raise venture capital! /s

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. You are guaranteed a response here!

New to React? Free, quality resources here

Want Help on Code?

  • Improve your chances of getting helped by putting a minimal example on to either JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new). Describe what you want it to do, and things you've tried. Don't just post big blocks of code.
  • If you got helped, 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.
51 Upvotes

454 comments sorted by

View all comments

Show parent comment

1

u/reactnewb Jul 04 '18 edited Jul 04 '18

Hey, swyx,

First and foremost - thank you for being here for me and others. I've been browsing in these threads and you seem like One Man Army at sharing knowledge.However, I've tried your method and it didn't give any results. While I don't fully understand binding (I want to try it practically and then break it down to pieces, it's my way to go), but I try to use it in constructor (ES5 style) everytime I write a function. Both this and your described way (I assume same as mine, but ES6 syntax?) haven't brought any results.

I assume that I am missing something essential, very basic, thus invisible to more experienced and null (I am new to programming so I like these geek jokes) to beginners like myself.

  1. write function that will be executed from a child (setState)
  2. bind it when in syntax (or constructor if you feel oldschoolish
  3. pass it as a prop to child
  4. execute as a prop in child
  5. ????
  6. PROFIT!

Am I missing a step? Thanks again and hope to hear again from you!

EDIT: After bunch of clicking, panicking, checking typos, reading - I found an issue - certainly a stupid one. I was passing the function to a wrong child. Now I just feel like a bad parent (/s).
Thanks again and for your sake - hope to never have to write here.
Cheers.

2

u/acemarke Jul 04 '18

Glad you got it worked out. I'd suggest taking the time to read through How and Why to Bind Methods in Your React Component Classes to help solidify your understanding.

2

u/swyx Jul 04 '18

yay rubber duck debugging!

dont worry it gets a lot easier. i know i struggled too when i started.