我们有一个错误边界组件:
import React from 'react';
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false, errorMessage:''};
}
componentDidCatch(error, info) {
// Display fallback UI
this.setState({ hasError: true, errorMessage: error });
// You can also log the error to an error reporting service
}
render() {
if (this.state.hasError) {
debugger
// You can render any custom fallback UI
return <h1>{this.state.errorMessage.toString()}</h1>;
}
return this.props.children;
}
}
export default ErrorBoundary;
Run Code Online (Sandbox Code Playgroud)
我们这样使用它:
ReactDOM.render(
<Provider store={store}>
<Router>
<CookiesProvider>
<ErrorBoundary>
<NetworkMgmt />
</ErrorBoundary> …Run Code Online (Sandbox Code Playgroud) error-handling reactjs react-router react-native react-redux
我们有一个 React Grid 组件,我们需要为所有 Grid 组件分配 Id。有什么建议我们该怎么做?组件片段如下所示:
<Grid
data={this.state.items}
sortable={{
allowUnsort: this.state.allowUnsort,
mode: this.state.multiple,
sortDir:this.state.sortDir
}}
sort={this.state.sort}
onSortChange={this.sortChange}
filterable={true}
filter={this.state.filter}
onFilterChange={this.filterChange}
onPageChange={this.pageChange}
total={this.state.total}
skip={this.state.skip}
pageSize={this.state.pageSize}
pageable={this.state.pageable}
scrollable={this.state.scrollable}
//style={{ height: '500px' }}
>
<Column
field="networkName"
sortable={{
allowUnsort: this.state.allowUnsort,
mode: this.state.multiple ? 'multiple' : 'single',
}}
onSortChange={this.sortChange} title="Network Name" width="400px" cell={NetworkNameCell} />
<Column field="networkGroups" title="Network Groups" width="250px" id="networkGroupsId"/>
<Column field="networkType" title="Network Type" width="250px" id="networkTypeId"/>
<Column field="providersCount" title="Assigned Providers" />
<Column field="locationsCount" title="Assigned Locations" />
<Column cell={this.DeleteCommandCell} title="Action" sortable={false} filterable={false} />
<span class="k-icon …Run Code Online (Sandbox Code Playgroud) reactjs ×2
javascript ×1
kendo-grid ×1
kendo-ui ×1
react-native ×1
react-redux ×1
react-router ×1