Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
fix: don't crash if initialState is null
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Nov 7, 2019
1 parent e871fdb commit 270fbdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/NavigationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Container = React.forwardRef(function NavigationContainer(
ref: React.Ref<NavigationContainerRef>
) {
const [state, setNavigationState] = React.useState<State>(() =>
getPartialState(initialState)
getPartialState(initialState == null ? undefined : initialState)
);

const navigationStateRef = React.useRef<State>();
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ it('initializes state for a navigator on navigation', () => {
});
});

it("doesn't crash when initialState is null", () => {
const TestNavigator = (props: any) => {
const { state, descriptors } = useNavigationBuilder(MockRouter, props);

return descriptors[state.routes[state.index].key].render();
};

const TestScreen = () => null;

const element = (
// @ts-ignore
<NavigationContainer initialState={null}>
<TestNavigator>
<Screen name="foo" component={TestScreen} />
</TestNavigator>
</NavigationContainer>
);

expect(() => render(element)).not.toThrowError();
});

it('rehydrates state for a navigator on navigation', () => {
const TestNavigator = (props: any) => {
const { state, descriptors } = useNavigationBuilder(MockRouter, props);
Expand Down

0 comments on commit 270fbdc

Please sign in to comment.