TeodorKolev TeodorKolev - 2 months ago 6x
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?


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