on master help sign in
fix: default data to object to avoid undefined access
dee2cd5Matt Condon (shrugs)
src/lib/useRouter.js+3−1
@@ -1,6 +1,8 @@
1import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
1import { useCallback, useMemo, useState, useRef, useEffect } from 'react';
2import { last, includes as _includes, findIndex } from 'lodash';
2import { last, includes as _includes, findIndex } from 'lodash';
3
3
4+const NULL_DATA = {};
5+
4/**
6/**
5 * @param primary whether or not this is the top-level router
7 * @param primary whether or not this is the top-level router
6 * @param names map of string to view key, used for consumer references
8 * @param names map of string to view key, used for consumer references
@@ -80,7 +82,7 @@ export default function useRouter({
80 const includes = useCallback(key => _includes(routes.map(r => r.key), key), [
82 const includes = useCallback(key => _includes(routes.map(r => r.key), key), [
81 routes,
83 routes,
82 ]);
84 ]);
83− const data = useMemo(() => last(routes).data, [routes]);
85+ const data = useMemo(() => last(routes).data || NULL_DATA, [routes]);
84 const Route = useMemo(() => views[peek().key], [views, peek]);
86 const Route = useMemo(() => views[peek().key], [views, peek]);
85
87
86 // Scroll to top of page with each route transition
88 // Scroll to top of page with each route transition