0

My target: to find ref of label and colorize it. Code used:

colorizeLabel(){
    ReactDOM.findDOMNode(this.refs.amountLabel).color('#ffffff');
}

<label itemRef="amountLabel">Choose Amount:</label>

which produce: Uncaught TypeError: Cannot read property 'color' of null

It looks like it is unable to find ref. Do I miss anything?

IntoTheDeep
  • 4,027
  • 15
  • 39
  • 84

1 Answers1

1

You need to specify ref in element

<label ref="amountLabel">Choose Amount:</label>

However it is advised to use ref as below

<label ref={(ref) => this.myLabel = ref} />

and you can access label as this.myLabel

anoop
  • 3,229
  • 23
  • 35