Skip to content

Commit 0b95a99

Browse files
perziDidier Franc
authored andcommitted
Pass props to component (#1)
1 parent bd06b24 commit 0b95a99

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ const App = ({ user }) => (
2828
#### With code splitting
2929

3030
You're not logged in ? `<Login />` component is the only loaded, `<Home />` will be loaded when the user will be logged in.
31+
32+
Use componentProps to pass props to lazy loaded component.
33+
3134
```jsx
3235
import Async from 'react-code-splitting'
3336

3437
import Login from './Login'
3538
const Home = () => <Async load={import('./Home')} />
39+
const LostPassword = (props) => <Async load={import('./LostPassword')} componentProps={props}/>
3640

3741
const App = ({ user }) => (
3842
<Body>
3943
{user.loggedIn ? <Route path="/" component={Home} /> : <Redirect to="/login" />}
4044
<Route path="/login" component={Login} />
45+
<Route path="/lostpassword" component={LostPassword} />
4146
</Body>
4247
)
4348
```

dist/react-code-splitting.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ var Async = function (_React$Component) {
3636
_this.C = c;_this.forceUpdate();
3737
});
3838
}, _this.render = function () {
39-
return _this.C ? _react2.default.createElement(_this2.C.default, null) : null;
39+
var componentProps = _this.props.componentProps;
40+
41+
return _this.C ? _react2.default.createElement(_this2.C.default, componentProps) : null;
4042
}, _temp), _possibleConstructorReturn(_this, _ret);
4143
}
4244

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ export default class Async extends React.Component {
55
this.props.load.then((c) => { this.C = c; this.forceUpdate() })
66
}
77

8-
render = () => this.C ? <this.C.default /> : null
8+
render = () => {
9+
const {componentProps} = this.props
10+
return this.C ? <this.C.default {...componentProps} /> : null
11+
}
912
}
1013

1114
Async.propTypes = {

0 commit comments

Comments
 (0)