mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-11 22:33:32 +08:00
refactor: mark initial state as stale to determine when to rehydrate (#23)
This commit is contained in:
committed by
Michał Osadnik
parent
2798c93e8b
commit
bd6aa667cb
@@ -86,9 +86,10 @@ const StackRouter: Router<CommonAction | Action> = {
|
||||
getRehydratedState({ routeNames, partialState }) {
|
||||
let state = partialState;
|
||||
|
||||
if (state.routeNames === undefined || state.key === undefined) {
|
||||
if (state.stale) {
|
||||
state = {
|
||||
...state,
|
||||
stale: false,
|
||||
routeNames,
|
||||
key: `stack-${shortid()}`,
|
||||
};
|
||||
|
||||
@@ -72,9 +72,10 @@ const TabRouter: Router<Action | CommonAction> = {
|
||||
getRehydratedState({ routeNames, partialState }) {
|
||||
let state = partialState;
|
||||
|
||||
if (state.routeNames === undefined || state.key === undefined) {
|
||||
if (state.stale) {
|
||||
state = {
|
||||
...state,
|
||||
stale: false,
|
||||
routeNames,
|
||||
key: `tab-${shortid()}`,
|
||||
};
|
||||
|
||||
@@ -3,9 +3,9 @@ import { render } from 'react-dom';
|
||||
import {
|
||||
NavigationContainer,
|
||||
CompositeNavigationProp,
|
||||
PartialState,
|
||||
NavigationProp,
|
||||
RouteProp,
|
||||
InitialState,
|
||||
} from '../src';
|
||||
import StackNavigator, { StackNavigationProp } from './StackNavigator';
|
||||
import TabNavigator, { TabNavigationProp } from './TabNavigator';
|
||||
@@ -143,7 +143,7 @@ const Fifth = ({
|
||||
|
||||
const PERSISTENCE_KEY = 'NAVIGATION_STATE';
|
||||
|
||||
let initialState: PartialState | undefined;
|
||||
let initialState: InitialState | undefined;
|
||||
|
||||
try {
|
||||
initialState = JSON.parse(localStorage.getItem(PERSISTENCE_KEY) || '');
|
||||
|
||||
Reference in New Issue
Block a user