javascript - How import a React component from github? -


i'm trying understand how react works.

i want use react-chartjs library. (https://github.com/jhudson8/react-chartjs). how can import in project?

i tried in way:

in file mycomponent.js:

var lc = react.createclass({ render: function(){     var xfield = this.props.xfield;     var yfield = this.props.yfield;     var data = {             labels: xfield,             datasets: [             {                 label: "my first dataset",                 fillcolor: "rgba(220,220,220,0.2)",                 strokecolor: "rgba(220,220,220,1)",                 pointcolor: "rgba(220,220,220,1)",                 pointstrokecolor: "#fff",                 pointhighlightfill: "#fff",                 pointhighlightstroke: "rgba(220,220,220,1)",                 data: yfield             }]         }       return(         <linechart data={data} width="600" height="250" />     );  }});   var mycomponent = react.createclass({  render: function(){     return(         <lc xfield={a} yfield={b} />     );   }});   react.render(<mycomponent />, document.getelementbyid('content')); 

i'm assuming e b arrays of values.

my index page this:

<html>   <head>     <!-- react --> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/jsxtransformer.js"></script> <script src="js/react-chartjs.js"></script> <script type="text/jsx;harmony=true" src="mycomponent.js"></script>  </head> <body>     <div id="content"></div> </body> 

react-chartjs.js should compiled chartjs component.

running index in way have error:

 uncaught referenceerror: linechart not defined 

i need use line

var linechart = require("react-chartjs").line; 

but in mycomponent.js have error require not defined

what's wrong??

in node.js require module in-built , in browser if have use require have use require.js or inherit script folder in html part <script type="text/jsx" src ="/path/to/the file/"></script>


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -