【发布时间】:2017-01-20 13:39:17
【问题描述】:
我正在使用 TypeScript(1.8.10) 并学习 react。我正在使用 React-Bootstrap 构建一个简单的导航作为示例,我收到以下错误。该错误阻止了 dom 被渲染。我对反应完全陌生,所以不确定我在这里做错了什么。非常感谢您提供任何帮助或提示以解决此错误。
// A '.tsx' file enables JSX support in the TypeScript compiler,
// for more information see the following page on the TypeScript wiki:
// https://github.com/Microsoft/TypeScript/wiki/JSX
/// <reference path="./../../../typings/index.d.ts" />
import * as React from 'react';
import * as ReactBootstrap from 'react-bootstrap';
interface INavigationProps {
}
let Navbar = ReactBootstrap.Navbar;
let NavItem = ReactBootstrap.NavItem;
let MenuItem = ReactBootstrap.MenuItem;
let NavbarHeader = ReactBootstrap.NavbarHeader;
const dropdownItems = [
{ href: '#', name: 'Overview' },
{ href: '#', name: 'Setup' },
{ href: '#', name: 'Usage' },
];
export default class Navigation extends React.Component<INavigationProps, {}> {
render() {
return (
<Navbar>
<NavbarHeader href="homepage.html" name="Website Name"/>
<NavItem>
<MenuItem link="about.html" title="About" />
<MenuItem link="contact.html" title="Contact" />
<MenuItem link="services.html" title="Services" />
</NavItem>
</Navbar>
);
}
}
// A '.tsx' file enables JSX support in the TypeScript compiler,
// for more information see the following page on the TypeScript wiki:
// https://github.com/Microsoft/TypeScript/wiki/JSX
/// <reference path="./../../typings/index.d.ts" />
import * as React from "react";
import * as ReactDOM from "react-dom";
import * as ReactBootstrap from 'react-bootstrap';
import HeaderNavigation from "./NavigationComponent/navigation";
import Hello from "./HelloComponent/Hello";
ReactDOM.render(
<div>
<HeaderNavigation />
<Hello name="Athraya" />
</div>,
document.getElementById("root")
);
【问题讨论】:
-
组件不是叫
Navigation,不是HeaderNavigation吗? -
@andrew headernavigation 只是一个标签,如您所见,它指向导航模块
标签: reactjs react-bootstrap typescript1.8