TeodorKolev TeodorKolev - 1 year ago 100
React JSX Question

ReactJs unable to find Ref

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


<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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download