I'm using react-router
with react-transition-group
to switch between full page components (think a simple book). However sometimes the next page has a few images. Therefore I don't want the next page to load until all the images / included CSS has also loaded. I don't mind having a loader before this transition takes place, waiting for the next component to load.
However I can't find any way to call events on the entire next component loading. componentDidMount()
on the incoming component doesn't recognize whether the images have loaded within the new component, so when the next component slides in, the images often aren't loaded, so it's not very smooth.
Here's my CSSTransition and Switch code:
const App = withRouter(({ location }) => (
<TransitionGroup>
<CSSTransition
key={location.key}
classNames='slide'
timeout={1000}
>
<Switch location={location}>
<Route path="/:page" component={Subpage} />
<Route path="/" exact component={Homepage} />
</Switch>
</CSSTransition>
</TransitionGroup>
))