var MyElement = React.createClass({displayName: "FormatParagraph",
render: function () {
return (
React.createElement("p", null, this.props.paragraph)
);
}
});
How can I add a style object to this?
If you need to style a Fragment then you probably shouldn't be using it in the first place. Fragments exists as a workaround to return adjacent JSX elements, they don't render anything to the DOM so they can't be stylized.
There are several ways to add styles to a component: By setting styles or styleUrls metadata. Inline in the template HTML. With CSS imports.
Use the React. CSSProperties type to pass CSS styles as props in React TypeScript, e.g. style: React. CSSProperties; . The CSSProperties type is used to type the style object that consists of CSS property names and values.
The second parameter to createElement
is a hash of attributes where the key is the attribute name and the value is the attribute value. The style
attribute takes a hash of style names to values. So, for example:
React.createElement("p", {style: {color: "red", backgroundColor: "blue"}}, this.props.paragraph)
React.createElement("p", {id : 'div1', className : 'news'}, this.props.paragraph)
This way you can use CSS specified in App.css
inside in an id/class
.
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