[英]React not rendering simple component
我是React的新手,所以这个问题。 我正在尝试渲染一个基本的React组件。 这是我的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>React</title>
</head>
<body>
<div id="root"></div>
<script src="/bundle.js"></script>
</body>
</html>
这是我的index.js
import React from 'react';
import 'babel-polyfill';
import { render } from 'react-dom';
import './styles/style.css';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import Layout from './components/Layout';
React.render(<Layout />, document.getElementById("root"));
这是我的布局组件。
import React from 'react';
import {render } from 'react-dom';
class Layout extends React.Component{
render(){
return(
<div className="container-fluid">
<div className="jumbotron">
<h1>This is home now</h1>
</div>
</div>
);
}
}
export default Layout;
这是我在控制台上看到的错误,
Uncaught TypeError: _react2.default.render is not a function
启动开发服务器时,我看到一个空白页面,没有呈现任何内容。 任何帮助表示赞赏。
从react-dom导入index.js内的render函数的方式会更改调用它的方式。
import { render } from 'react-dom';
在这里,您只需从react-dom对象导入render方法。 所以要使用它,你会说
render(<Layout />, document.getElementById("root"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.