I have defined a class name for the table below (as part of JSX).<table class="table">
However once its displayed the class is not set on the table:
var SearchResult = React.createClass({
render: function(){
return (
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
</thead>
<tbody>...</tbody>
</table>
);
}
});
Instead the table shows as <table data-reactid=".0.1.0.0">...</table>
in Chrome -> inspect element.
In class-based components, the className attribute is used to set or return the value of an element's class attribute. Using this property, the user can change the class of an element to the desired class.
Explanation: The only reason behind the fact that it uses className over class is that the class is a reserved keyword in JavaScript and since we use JSX in React which itself is the extension of JavaScript, so we have to use className instead of class attribute.
ReactJS uses the attribute className
to avoid the use of a JavaScript reserved word.
<table className="table">
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