Skip to content

Unsure how to use library in app: "React is not defined" #16

Description

@TAGC

I'm developing an app and trying to import this library to use it. I've installed it using Yarn and I'm using Webpack to bundle it up along with my other dependencies.

I have a simple React component JSX file like this:

import * as React from 'react';
import TreeView from 'react-bootstrap-treeview/public/js/react-bootstrap-treeview';

//noinspection JSUnusedLocalSymbols
export default function SideBar (_: {}) {
  return (
      <TreeView/>
  );
}

When I try to render this, I get an error "React is not defined" coming from "react-bootstrap-twitter.js". The reason is that it expects "React" to be a globally defined variable.

For reference, this is the start of "react-bootstrap-twitter":

var TreeView = React.createClass({displayName: "TreeView",

  propTypes: {
    levels: React.PropTypes.number,

    expandIcon: React.PropTypes.string,
    // ...

I'm pretty new to web stuff and I have no idea how to make React globally available within my app, but wouldn't it make more sense to declare React as a peer dependency and import/require it at the top of the file?

Is there a way I can adapt my code to let me use TreeView?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions