I'm trying to change background of a div
when color value changes. Here is my function which receives color value:
ChangeColor(oColor) { this.props.ChangeColor(oColor); console.log("Refs: ", this.refs.colorPicker.className); },
Here is css class
.colorPicker { padding-right: 25px; background: #000; display: inline; margin-right: 5px; }
and here is my div element whose background needs to update on run-time.
<div ref='colorPicker' className={this.GetClass("colorPicker")} />
I'm not sure about refs synatx so please help to fix this issue. Thanks.
Refs are a function provided by React to access the DOM element and the React element that you might have created on your own. They are used in cases where we want to change the value of a child component, without making use of props and all.
I found it. Here is answer:
ChangeColor(oColor) { this.props.ChangeColor(oColor); this.refs.colorPicker.style.background = oColor; //this is how background will be updated },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With