1

Running ES6 on top of Reactjs. Suppose I want to reference a node with firstName like this:

var el = React.findDOMNode(this.refs.firstName);

but type = 'firstName'. So I need to do something like this:

var el = React.findDOMNode(this.refs.{type});

And I've tried a handful of different variations and nothing works. I know the answer is very simple but I can't find it as I'm very much a newbie! I think this relates to string literals? Thanks in advance for your help!

PhilVarg
  • 4,762
  • 2
  • 19
  • 37
missbarium
  • 131
  • 2
  • 11
  • I'm not sure i get what you mean by helped in the variable type. can you post what your `type` variable is? does `type` equal the string `'firstName'`, is it an object with key `type` etc? – PhilVarg Jul 01 '15 at 19:24
  • Sure, just edited, sorry for the confusion! – missbarium Jul 01 '15 at 19:29

1 Answers1

1

In this case, you want to make use of javascripts bracket notation for accessing object properties

this.refs[type] instead of this.refs.type

Community
  • 1
  • 1
PhilVarg
  • 4,762
  • 2
  • 19
  • 37