Skip to content

Commit

Permalink
feat: add prop to disable the initial props cache (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
crash7 authored Oct 7, 2019
1 parent bdaa459 commit f7ccc21
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/client/flow-typed/beforeComponent_vx.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ declare module 'Before.component' {
+staticContext?: StaticRouterContext,
+data: ?DataType,
+routes: Array<AsyncRoute>,
+req: Request
+req: Request,
+disableInitialPropsCache: Boolean
|};

declare module.exports: {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/Before.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const reducer = (state: BeforeState, { location, type }: BeforeAction) => {
* @function
*/
export function Before(props: BeforeComponentWithRouterProps) {
const { data, routes, location, req, history } = props;
const { data, routes, location, req, history, disableInitialPropsCache } = props;
const [state, dispatch] = useReducer(reducer, {
currentLocation: location
});
Expand Down Expand Up @@ -192,7 +192,7 @@ export function Before(props: BeforeComponentWithRouterProps) {
useEffect(() => {
const unlisten = history.listen((location, action) => {
interrupt.current = action === 'POP';
if (!initialProps.current[location.pathname]) {
if (disableInitialPropsCache || !initialProps.current[location.pathname]) {
// This solves a weird case when, on an advanced step of the flow, the user does a browser back
const route = getRouteByPathname(location.pathname, routes);
if (route) {
Expand Down

0 comments on commit f7ccc21

Please sign in to comment.