javascript - ReactDOM.render() unresolved -
import react 'react'; // import reactdom 'react-dom'; import reactdom 'react-dom/dist/react-dom.min'; import {alert} 'reactstrap'; class alertline extends react.component { constructor(props) { super(props); this.state = { visible: true }; } ondismiss = () => { this.setstate( { visible: false } ); }; render() { return ( <div> <alert color="success" isopen={this.state.visible} toggle={this.ondismiss}> <strong>success!</strong> read important alert message. </alert> </div> ); } } reactdom.render( <alertline/>, document.getelementbyid('root') );
reactdom.render() works fine 'react-dom' development. however, try import minified 'react-dom.min' instead of 'react-dom', render() goes unresolved , nothing happens. can't find render() content assist(ctrl + space) neither.
i've installed react@15.6.1 , react-dom@15.6.1 npm , they're on 'npm list'. tried reinstall them didn't work.
non-module
node modules loaded require / import must populate exports object module wants make public.
stackoverflow.com/a/14914442/6836839
react-dom.min.js
used simple js library, can't import
/ require
install
since can't require / import, need load normal js
script:
<!-- index.html --> <script src="node_modules/react-dom/dist/react-dom.min.js"></script>
use
// call it... reactdom.render(component, document.getelementbyid('root'))
note
if load react tag, these top-level apis available on reactdom global.
if use es6 npm, can write import:
import reactdom 'react-dom'
if use es5 npm, can write:
var reactdom = require('react-dom');
Comments
Post a Comment