Search code examples
react-nativereactstrap

How do I use the reactstrap components with a react native app?


I am trying to use reactstrap with react native but I keep getting an error when running the demo:

Invariant Violation: View config not found for name a

This error is located at:
    in a (created by NavbarBrand)
    in NavbarBrand (at App.js:58)
    in nav (created by Navbar)
    in Navbar (at App.js:57)
    in div (at App.js:56)
    in App (created by AwakeInDevApp)
    in RCTView (at View.js:113)
    in View (created by AwakeInDevApp)
    in AwakeInDevApp (at registerRootComponent.js:34)
    in RootErrorBoundary (at registerRootComponent.js:33)
    in ExpoRootComponent (at renderApplication.js:35)
    in RCTView (at View.js:113)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:113)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:34)

The code I am running is:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {
  Collapse,
  Navbar,
  NavbarToggler,
  NavbarBrand,
  Nav,
  NavItem,
  NavLink,
  UncontrolledDropdown,
  DropdownToggle,
  DropdownMenu,
  DropdownItem } from 'reactstrap';

export default class App 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="faded" 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 >
                  <DropdownItem>
                    Option 1
                  </DropdownItem>
                  <DropdownItem>
                    Option 2
                  </DropdownItem>
                  <DropdownItem divider />
                  <DropdownItem>
                    Reset
                  </DropdownItem>
                </DropdownMenu>
              </UncontrolledDropdown>
            </Nav>
          </Collapse>
        </Navbar>
      </div>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

My install is as follows:

npm install -g create-react-native-app
create-react-native-app AwesomeProject
cd AwesomeProject

npm install --save bootstrap@4.0.0-beta.3
npm install --save reactstrap@next react-dom@^16.0.0
npm install --save jquery@1.9.1

I am using: node v7.10.1 npm 4.2.0


Solution

  • Reactstrap cannot be used in react native because it is targeted at html. For reusable components you might want to look at https://github.com/react-native-training/react-native-elements.

    Edit:

    This previous repository has been archived by the owner. It is now read-only.

    Here's the new repo: https://github.com/react-native-elements/react-native-elements

    If you are having any issues accessing the docs, please note that they are available at a new URL: https://react-native-elements.github.io/react-native-elements/