我正嘗試使用在我的React項目中看起來很有希望的Ag-grid。在React項目中使用Ag-grid時出錯
我做了一個非常簡單的組件最基本的電網可能和我得到一個錯誤:
Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of
UserList
如果我刪除的渲染()方法<AgGridReact columnDefs={this.state.columnDefs} rowData={this.state.users} />
,頁面再次顯示正確。
什麼可能是錯的..?
這裏是我的組件代碼:
import React from 'react';
import ReactDOM from 'react-dom';
import AgGridReact from 'ag-grid-react';
$ = window.$ = window.jQuery = require('jquery');
var UserList = React.createClass({
getInitialState: function() {
return {
showGrid: true,
users: [],
columnDefs: []
};
},
getDefaultProps: function() {
return {
};
},
componentDidMount: function() {
var self = this;
// $.ajax({
// url: 'http://localhost:55010/api/v1/User',
// type: 'GET',
// data: null,
// contentType: "application/json; charset=utf-8",
// dataType: "json",
// success: function (data) {
// self.setState({ users: data });
// },
// error: function (jqXHR, b, c) {
// }
// });
},
componentWillUnmount: function() {
},
// onShowGrid: function(show) {
// this.setState({
// showGrid: show
// });
// },
// onGridReady: function(params) {
// this.api = params.api;
// this.columnApi = params.columnApi;
// },
render: function() {
return (
<div>
<h1>UserList</h1>
<ul>
{this.state.users.map(function(u) {
return (
<li key={'u'+u.Id}>
{u.Id}, {u.Username}, {u.Email}
</li>
);
})}
</ul>
<div style={{width: '800px'}}>
<div style={{padding: '4px'}}>
<div style={{height: 400}} className="ag-fresh">
<AgGridReact columnDefs={this.state.columnDefs} rowData={this.state.users} />
</div>
</div>
</div>
</div>
);
}
});
module.exports = UserList;