0

I have a meteor application which uses react at the front-end. I have installed bootstrap using npm (not atmospherejs), and I'm having trouble using the bootstrap styles in my react component. Here's the code for my main component.

import React from 'react';

import Bootstrap from 'bootstrap';

const Layout = ({content = () => null }) => (

  <div>
   <div className="row">
     <div className="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
     <div className="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>      
     <div className="clearfix visible-xs-block"></div>
     <div className="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
   </div>
  </div>  
);

export default Layout;

I'm new to react. Can someone tell me what's missing here and what I'm doing wrong?

6
  • 1
    The styles are defined in CSS. You're importing the JavaScript. Commented Apr 11, 2016 at 4:38
  • Are you using systemjs or webpack? Commented Apr 11, 2016 at 4:38
  • @DovBenyominSohacheski it's meteor so I don't have to use a bundling package right? Commented Apr 11, 2016 at 4:40
  • So what's the correct way to use it? Commented Apr 11, 2016 at 4:43
  • @ThaiTran I'm using a stateless component here. That's why I don't have the React.createClass. Commented Apr 11, 2016 at 5:00

2 Answers 2

1

I assume that you want to import Bootstrap's CSS to use the appropriate classes in your component. This can be done with Webpack:

installation

Install the loaders from npm.

npm install style-loader css-loader --save-dev

configuration

Here is a configuration example that enables require() css:

{
    // ...
    module: {
        loaders: [
            { test: /\.css$/, loader: "style-loader!css-loader" }
        ]
    }
}

using css

// in your modules just require the stylesheet
// This has the side effect that a <style>-tag is added to the DOM.
require("./stylesheet.css");

// or
// import "./stylesheet.css";
Sign up to request clarification or add additional context in comments.

1 Comment

Since I'm using meteor, I don't think there's a point using a bundling tool like Webpack, am I correct @Pavlo?
0

This seems to be a known problem with Meteor. So I guess I'll have to depend on alternatives until MDG find a solution.

Style files imports from node_modules

1 Comment

Please include relevant parts in the answer itself, this will prevent the answer from link rot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.