Reactjs 创建react应用程序示例应用程序问题
我正在尝试创建一个示例create react应用程序:Reactjs 创建react应用程序示例应用程序问题,reactjs,Reactjs,我正在尝试创建一个示例create react应用程序: create-react-app my-app cd my-app/ npm start 现在它说编辑src/App.js,好的。。。 我想使用react组件 现在,在该页面上有一个“基本示例”,当我将其粘贴到src/App.js中时,会出现很多错误-经过一些编辑后,我将其归结为: import React from 'react'; import ReactDOM from 'react-dom'; import { Table, C
create-react-app my-app
cd my-app/
npm start
现在它说编辑src/App.js,好的。。。
我想使用react组件
现在,在该页面上有一个“基本示例”,当我将其粘贴到src/App.js中时,会出现很多错误-经过一些编辑后,我将其归结为:
import React from 'react';
import ReactDOM from 'react-dom';
import { Table, Column, Cell } from 'fixed-data-table';
// Table data as a list of array.
const rows = [
['a1', 'b1', 'c1'],
['a2', 'b2', 'c2'],
['a3', 'b3', 'c3'],
// .... and more
];
// Render your table
ReactDOM.render(
<Table
rowHeight={50}
rowsCount={rows.length}
width={5000}
height={5000}
headerHeight={50}>
<Column
header={<Cell>Col 1</Cell>}
cell={<Cell>Column 1 static content</Cell>}
width={2000}
/>
</Table>,
document.getElementById('example')
);
从“React”导入React;
从“react dom”导入react dom;
从“固定数据表”导入{表、列、单元格};
//表数据作为数组的列表。
常量行=[
['a1','b1','c1'],
['a2','b2','c2'],
[a3',b3',c3'],
//……还有更多
];
//把你的桌子摆好
ReactDOM.render(
,
document.getElementById('示例')
);
这给了我以下错误:
我做错了什么?这是因为您试图在不存在的元素中呈现React,请将
document.getElementById('example')
更改为document.getElementById('root')
更新
您的App.js文件应该使用React组件类中的render()
函数来实现:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import { Table, Column, Cell } from 'fixed-data-table';
// Table data as a list of array.
const rows = [
['a1', 'b1', 'c1'],
['a2', 'b2', 'c2'],
['a3', 'b3', 'c3'],
// .... and more
];
// Render your table
class App extends Component {
render () {
return (<div>
<div>Hello world</div>
<Table
rowHeight={50}
rowsCount={rows.length}
width={5000}
height={5000}
headerHeight={50}>
<Column
header={<Cell>Col 1</Cell>}
cell={<Cell>Column 1 static content</Cell>}
width={2000}
/>
</Table>
</div>)
}
}
export default App;
谢谢现在我得到:
React.createElement:type无效——应该是字符串(对于内置组件)或类/函数(对于复合组件),但得到:undefined。您可能忘记了从定义组件的文件中导出组件。请在index.js:7查看您的代码。
再次感谢。嗯,现在我没有收到任何错误,但我也没有看到我的表。也许那个组件是个哑弹。你看到了吗?向下滚动到页面底部,您应该可以看到内容。
ReactDOM.render(<App />, document.getElementById('root'));