Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
React not working with Bootstrap

I am starting a new project where I am using Flask + React + Bootstrap, but the Bootstrap within JSX is not working for some reason.

I am using gulp-react to transform JSX into JS.

Here is the JSX (literally an example from bootstrap website):

var Example = React.createClass({
  render: () => {
    return (
      <div class="input-group">
        <span class="input-group-addon" id="basic-addon1">@</span>
        <input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1" />
      </div>
    )}
});

ReactDOM.render(
  <Example />,
  document.getElementById('main')
);

and the transformed JS:

var Example = React.createClass({displayName: "Example",
  render: function()  {
    return (
      React.createElement("div", {class: "input-group"}, 
        React.createElement("span", {class: "input-group-addon", id: "basic-addon1"}, "@"), 
        React.createElement("input", {type: "text", class: "form-control", placeholder: "Username", "aria-describedby": "basic-addon1"})
      )
    )}
});

ReactDOM.render(
  React.createElement(Example, null),
  document.getElementById('main')
);

When I copy and paste the HTML into the HTML template, everything appears as expected. When I replace Example.render with a simple <h1>Text</h1>, it also renders fine.

What could be the problem?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When we write JSX, we're still writing in JavaScript, just with some different syntax. In JavaScript 'class' is a keyword, which means we can't use 'class' unless we're actually trying to define one. So to work around this, you have to replace 'class' with 'className' as such:

var Example = React.createClass({
  render: () => {
    return (
      <div className="input-group">
        <span className="input-group-addon" id="basic-addon1">@</span>
        <input type="text" className="form-control" placeholder="Username" aria-describedby="basic-addon1" />
      </div>
    )}
});

ReactDOM.render(
  <Example />,
  document.getElementById('main')
);

In your .html files, however, you wouldn't use 'className', it'd just be 'class' like you were trying to do originally.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!