Open wildhart opened 6 years ago
Sorry, I forgot I'd already raised this here https://github.com/ManuelDeLeon/viewmodel-react-plugin/issues/4
I had given up on upgrading Meteor for a while, but wanted to try again. Any new help would be appreciated though.
I know this is a dirty hack but your route could point to a component that would encapsulate your deferred component...
I had problems with defer binding with Inferno, and am not sure how they are managed internally
Hi @antoninadert ,
That's exactly what I ended up doing. It's a bit tricky because you can't pass a path variable to an import(path)
statement. Instead every deferred route needs it's own import()
statement. I can't remember where I found this code:
// Defer.jsx
import React, { Component } from 'react';
export class Defer extends Component {
_isMounted = true;
state = {
Bar: null
};
componentWillMount() {
let p;
switch (this.props.d) {
case 'AppHome': p = import('./AppHome/AppHome'); break;
case 'Help': p = import('./Help/Help'); break;
case 'Edit': p = import('./Edit/Edit'); break;
// etc...
}
p && p.then(mod => this._isMounted && this.setState({Bar: mod[this.props.d]})).catch(error => console.log('defer error: ', error));
}
componentDidUpdate(prevProps, prevState) {
if (this.props.d && this.props.d != prevProps.d) this.componentWillMount();
}
componentWillUnmount() {
this._isMounted = false;
}
render() {
let {Bar} = this.state;
return Bar ? <Bar {...this.props} /> : null;
}
}
Then I can do this:
<Switch>
<Route path="/app" render={(props) => <Defer d="AppHome" {...props} />} />
<Route path="/help" render={(props) => <Defer d="Help" {...props} />} />
</Switch>
I've tried upgrading from Meteor 1.6 to Meteor 1.7 then Meteor 1.8, and with both
b="defer:true"
in a react-route no longer compiles:gives this compile error:
It was working perfectly before.
I've upgraded to Meteor 1.8 with:
Any ideas?