From @rtmalone on Wed Aug 30 2017 17:00:44 GMT+0000 (UTC)
Great article; thanks for detailing the ‘why’ in some of the decisions. I immediately added an AsyncComponent in three of my apps. I wondering though how to descriptively name the chunks to correspond to the component or file name. Any thoughts?
From @bestwestern on Wed Oct 18 2017 07:39:36 GMT+0000 (UTC)
Thank you very much for this. I am looking for a way to preload some routes (without react-loadable).
Right now I simply call componenDidMount(){ import("./containers/Login"); }
which seems to do the trick
From @jayenashar on Mon Dec 18 2017 00:48:26 GMT+0000 (UTC)
Hi there, I’m pretty new to react and am not using redux. I have implemented code splitting with an async component as described in this chapter and it works great. However, I call child component instance methods from parent components (e.g., childComponentRef.triggerABC()). I’m not sure the proper way to do this with the AsyncComponent as a proxy, but I would like to share what I have done.
First, I save a ref of the child component: <C {...this.props} /> becomes <C {...this.props} ref={c => c && (this.c = c)} />
Second, I return a Proxy: return AsyncComponent; becomes
From @jayair on Thu Dec 21 2017 19:22:00 GMT+0000 (UTC)
@jayenashar I have not had a chance to try out the pattern of calling instance methods for async components. Hopefully, somebody else that comes across this has some ideas.
From @jayenashar on Tue Dec 26 2017 09:58:47 GMT+0000 (UTC)
@jayair the proxy got too complicated when i realised i needed to applythis for functions. i got it working, but threw it out. instead i use innerRef a la styled-components. Separate to that, I saw a warning when calling this.setState if the component unmounts while importing. I also opted not to use async/await as it added to the bundle size. I provide my modified functions below:
Having an issue with the Loadable library - my “loading” component shows up immediately, even if for only a split second, whether or not I have the delay property set. Has anyone else encountered this? I eliminated the additional routing wrappers and used simply Route but the issue persisted. Here’s the relevant libraries/versions:
react@16.6.1
react-router-dom@4.3.1
react-loadable@5.5.0
I did read through that - my understanding was that this functionality comes out of the box (props.pastDelay is part of the Loadable component) with a default delay prop of 200ms. Whether or not I have the delay prop set, the loader still flashes.
The prop that gets set in the Loadable component is delay which then sets the internal pastDelay prop. The spinner is flashing whether I set this delay prop or not. My router code is here, and the site here.
The delay prop is set to 500 for both the Home and Login page, and it is not set for the Signup page. All three flash the loading icon in the top left corner.
Unfortunately I can’t open an issue against the repo as it isn’t publicly available to do so.
This is great thanks - what if I am wanting to pass props to the Async-loaded component? The above seems to assume I’m rendering <Home /> - but what if I want to render <Home foo="bar" /> ?
Hey, I am trying to refactor the code from the chapter to use react hooks but am doing something wrong and can’t figure it out, maybe someone has some ideas on how to help me?
Here is my code for the src/components/AsyncComponent.js :
Hey there, I’m not entirely sure about your issue. But this chapter needs to be updated to use React Suspense, since they added native support for this.