Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify class on a JSX node?

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.

like image 332
Houman Avatar asked Jan 05 '15 15:01

Houman


People also ask

What is JSX className?

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.

Why does JSX use className instead of 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.


1 Answers

ReactJS uses the attribute className to avoid the use of a JavaScript reserved word.

<table className="table">
like image 74
couchand Avatar answered Oct 13 '22 18:10

couchand