I am trying to do something like this in ReactJS:
var MyReactClass = React.createClass({ render: function() { var myDivText = "Hello!"; var myFontSize = 6; //this is actually something more complicated, I'm calculating it on the fly var divStyle = { font-size: {fontSize + 'px !important;'}, }; return (<div style={divStyle}>{myDivText}</div>); } });
The problem is that I get this error when I run my code: "Module build failed: Error: Parse Error: Line 5: Unexpected token -" apparently, React doesn't like that font-size
has a dash in it. How do I get around this? Is there some way to escape that character for react? Is there some different css property that react likes better that does the same thing?
Thanks!
To change font size of text field in React Material UI, we can set the InputProps and the InputLabelProps prop to set the font size of the input box and the input label respectively. to set InputProps and InputLabelProps to { style: { fontSize: 40 } } so that the input box and the label both have font size 40px.
To change the size of your text with inline CSS, you have to do it with the style attribute. You type in the font-size property, and then assign it a value.
In React, inline styles are not specified as a string. The style attribute accepts a JavaScript object with camelCased properties. Below are the basic steps for defining inline CSS: 1. Change the CSS property name to its camelCase version like "background-color" to "backgroundColor", "font-size" to "fontSize", etc.
Use fontSize
instead of font-size
the solution is to camelCase properties which usually contain a dash
http://facebook.github.io/react/tips/inline-styles.html
Answered my own question :)
As https://reactjs.org/docs/dom-elements.html says,
We need to remove '-' and upperCase except first word
Example-background-color as backgroundColor,
Same will be applicable everywhere except a few as-
aria-* and data-*
example-
aria-label as aria-label
Above worked for me!
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