So I have some nested routes that look like this:
<Switch>
<Route exact path={"/"}>
<HomepageContainer />
</Route>
<Route path={"/users"}>
<UsersContainer />
</Route>
<Route path={"/users/new"}>
<NewUserContainer />
</Route>
<Route path={"/users/:userId/edit"}>
<EditUserContainer />
</Route>
<Route path={"/users/:userId/comments"}>
<UserCommentsContainer />
</Route>
<Route path={"/users/:userId/comments/:commentId"}>
<UserCommentContainer />
</Route>
<Route render={() => <Redirect to={"/"} />} />
</Switch>
Three of which have a userId in the URL params and inside those components I fetch a user inside of a useEffect hook.
Is there a way for react-router-dom to allow me to do this fetch in a single place and make the result available to EditUserContainer, UserCommentsContainer and UserCommentContainer?