Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TAGC opened this issue Apr 19, 2017 · 0 comments
Open

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

TAGC opened this issue Apr 19, 2017 · 0 comments

Comments

@TAGC
Copy link

TAGC commented Apr 19, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant