Check out example codes for "javascript add inline style css var". It will help you in understanding the concepts better.

Code Example 1

element.style.setProperty("--my-var", jsVar + 4);

Learn ReactJs, React Native from akashmittal.com