Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sdd/match-async
react-router v4 Match component replacement that handles code split async components
https://github.com/sdd/match-async
Last synced: 15 days ago
JSON representation
react-router v4 Match component replacement that handles code split async components
- Host: GitHub
- URL: https://github.com/sdd/match-async
- Owner: sdd
- Created: 2016-09-26T16:30:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T05:25:14.000Z (about 1 year ago)
- Last Synced: 2024-10-31T00:08:50.436Z (2 months ago)
- Size: 1000 Bytes
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# match-async
react-router v4 Match component replacement that handles code split async components```javascript
import React, { Component } from 'react';const asyncComponent = path => class extends React.Component {
componentWillMount() {
if (!this.state) {
require.ensure(path) // or System.import
.then(module => {
this.setState({ Component: module.default })
});
}
}
render() {
const { Component } = this.state;
return Component && ;
}
}class MatchAsync extends Component {
constructor(props) {
super(props);
const { path } = this.props;
this.state = { component: asyncComponent(path) }
}
render() {
const { path, ...props } = this.props;
const { component } = this.state;
return ;
}
}const App = () =>
```