React with a reaction bootstrap. How do they use it?

I just started researching react and tried to figure out how to use react-bootstrap when installed on bower. I just started after that but I really don't understand how this is supposed to work.

here i have markup

<!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
        <title>Bootstrap 101 Template</title>

        <!-- Bootstrap -->
        <link href="styles/main.css" rel="stylesheet">
        <script src="vendor/react/react.js"></script>
        <script src="vendor/react-bootstrap/react-bootstrap.js"></script> 
        <script src="vendor/react/JSXTransformer.js"></script>

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
      </head>
      <body>


         <script>
            var Alert = ReactBootstrap.Alert;
            console.log(Alert)
        </script>

        <!-- jQuery (necessary for Bootstrap JavaScript plugins) -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
      </body>
    </html>

      

How do I create a bootsrap component with this package?

Update

I think I have this, but I'm not sure if I'm using it correctly in my markup

 <script>
        var Alert = ReactBootstrap.Alert;
 </script>

 <script src="components/Alert.js"></script>

      

Alert.js

is the compiled jsx

const alertInstance = (
  <Alert bsStyle='warning'>
    <strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
  </Alert>
);

React.render(alertInstance, document.body);

      

+3


source to share


1 answer


@dmasi mentioned this in the comments. This is similar to the namespace issue and lack of it in the examples mentioned on the react-bootstrap website.

Here's an example using Bootstrap ButtonGroup via React-Bootstrap. You can use a similar approach for your code.



<h2>React-Bootstrap Testing</h2>
<div id="myBtn"></div>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-bootstrap/0.25.1/react-bootstrap.js"></script>

<script type="text/jsx">
    var MyReactBootstrapButton = React.createClass({
    render: function() {

        var ButtonGroup = ReactBootstrap.ButtonGroup,
            Button  = ReactBootstrap.Button;

        return (<div>
                    <ButtonGroup>
                        <Button>Left</Button>
                        <Button>Middle</Button>
                        <Button>Right</Button>
                    </ButtonGroup>
                </div>);
    }
});

React.render(<MyReactBootstrapButton />, document.getElementById("myBtn"));
</script>
      

Run codeHide result


Working fiddle link: fiddle

+6


source







All Articles