Reputation: 835
I created a react app with 'create react-app'.
I am trying now to add a navbar from Reactstrap. I do copy-paste from Reactstrap (I am adding this as one react component) website:
import React from 'react';
import {
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
UncontrolledDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem } from 'reactstrap';
export default class Example extends React.Component {
constructor(props) {
super(props);
this.toggle = this.toggle.bind(this);
this.state = {
isOpen: false
};
}
toggle() {
this.setState({
isOpen: !this.state.isOpen
});
}
render() {
return (
<div>
<Navbar color="light" light expand="md">
<NavbarBrand href="/">reactstrap</NavbarBrand>
<NavbarToggler onClick={this.toggle} />
<Collapse isOpen={this.state.isOpen} navbar>
<Nav className="ml-auto" navbar>
<NavItem>
<NavLink href="/components/">Components</NavLink>
</NavItem>
<NavItem>
<NavLink href="https://github.com/reactstrap/reactstrap">GitHub</NavLink>
</NavItem>
<UncontrolledDropdown nav inNavbar>
<DropdownToggle nav caret>
Options
</DropdownToggle>
<DropdownMenu right>
<DropdownItem>
Option 1
</DropdownItem>
<DropdownItem>
Option 2
</DropdownItem>
<DropdownItem divider />
<DropdownItem>
Reset
</DropdownItem>
</DropdownMenu>
</UncontrolledDropdown>
</Nav>
</Collapse>
</Navbar>
</div>
);
}
}
and it does not work. I am getting this in my react app:
I had similar problems with Bootstrap, React and Navbar before but I am really surprised it is happening in Reactstrap. Do you know why is it so?
Upvotes: 14
Views: 24277
Reputation: 19
just install
npm install bootstrap
npm install jquery
then import them in index.js
import 'bootstrap/dist/css/bootstrap.min.css';
import "jquery/dist/jquery.min.js";
import 'bootstrap/dist/js/bootstrap.bundle'
it worked for me while i am fail to toggle.
for more fetures you can install popper as well
Upvotes: 0
Reputation: 2117
While it's not documented, you have to use as follows with react-router:
<NavLink tag={Link} to="/somewhere">
IE:
import React from 'react';
import { Link } from 'react-router';
import { NavLink } from 'reactstrap';
const Example = (props) => {
return (
<NavLink tag={Link} to="/somewhere">
{props.item.name}
</NavLink>
);
};
Upvotes: 0
Reputation: 61
You should make sure you have
import 'bootstrap/dist/css/bootstrap.css';
imported into the index.js
file created automatically when you create react app.
Upvotes: 6
Reputation: 196
You need also bootstrap, and react-dom:
npm install --save bootstrap
npm install --save reactstrap react react-dom
import 'bootstrap/dist/css/bootstrap.css';
import { Button } from 'reactstrap';
Upvotes: 18
Reputation: 680
You can do this.
import { NavLink } from 'reactstrap';
import { NavLink as ReactLink } from 'react-router-dom';
<NavLink tag={ReactLink} to="/home" activeClassName="active" >Home</NavLink>
Upvotes: 2