-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use library with code splitting with React.lazy and use declarative routing? #158
Comments
@fedulovivan did you end up finding a solution for declarative routing? A fork or another package? |
@alaycock Yes, finally I have managed to launch our legacy code with latest version of redux-connect, but this approach required to use some monkey-patching and final solution appeared to be not that elegant (I even cannot remember what particulary was changed). const PageComponent: React.FC<PageComponentProps> = (): JSX.Element => {
// state
const [startInitialLoadTriggered, setStartInitialLoadTriggered] = useState(false);
// selectors
const isPendingInitialLoad = useSelector(selectors.isPendingInitialLoad);
// actions
const startInitialLoad = useAction(actions.startInitialLoad);
// effects
// trigger initial load
useEffect(() => {
setStartInitialLoadTriggered(true);
startInitialLoad();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// minor imperfection after elimination of redux-connect:
// we need to skip first render
// since effect with startInitialLoad is not yet executed
if (!startInitialLoadTriggered) return null;
return (
<Page title={PAGE_TITLE} bodyClassName={style.root}>
</Page>
);
} action startInitialLoad is handled by folowing epic which triggers fetching of required data // fetch initial data on page load
(action$, state$) => action$.pipe(
ofType(actions.startInitialLoad.TYPE),
mergeMap(() => {
return of(
actions.fetchEtities(),
actions.fetchEtitityAttributes(),
);
})
), isPendingInitialLoad selector returns true if any of async operations (fetch requests) are still in progress. |
Thanks, @fedulovivan for the response and the example! I was exploring something similar, but removing redux-connect also seems like a potential solution. |
@alaycock Were you able to remove |
@abhagsain we're still running it. There's some pretty tight coupling between |
Got it. @alaycock could you please tell me which version of |
@abhagsain your best bet is to look at the package.json for the peer dependencies if you haven't already. You should be able to upgrade to a more recent version of React without any issues while continuing to use react-router 3. That is a small step forward. As for our versions, we're pretty far behind. We're on I haven't actually looked into if that's reasonable or possible, so you'll have to do your own exploration. |
Say with have several modules, one for each page. Each of them is pretty heavy, and its not an option to load them all in advance to prepare static routes map as demonstrated in example (
const routes = [{ path: '/foo', component: Page1 },...];
)Each module contains async-connected page component + appropriate reducer.
first create lazy wrappers for each page:
injectAsyncReducer
function re-configures store and injects reducer for certain page using replaceReducer redux utility.now init provider, router, suspense-wrapper, define routes and mount tree:
so the question, where is the place for
<ReduxAsyncConnect>
component here?The text was updated successfully, but these errors were encountered: