@@ -1,4 +1,4 @@
1−import React, { useContext, useState, useEffect } from 'react';
1+import React, { forwardRef, useContext, useState, useEffect } from 'react';
2import { last, includes } from 'lodash';
2import { last, includes } from 'lodash';
4import { BRIDGE_ERROR } from '../lib/error';
4import { BRIDGE_ERROR } from '../lib/error';
@@ -29,10 +29,9 @@ export function HistoryProvider({ initialRoutes = [], children }) {
31 // Scroll to top of page with each route transition.
31 // Scroll to top of page with each route transition.
33− window.scrollTo(0, 0);
32+ useEffect(() => window.scrollTo(0, 0), [history]);
36 useEffect(() => {
35 useEffect(() => {
37 window.history.pushState(null, null, null);
36 window.history.pushState(null, null, null);
@@ -40,6 +39,8 @@ export function HistoryProvider({ initialRoutes = [], children }) {
40 window.history.pushState(null, null, null);
39 window.history.pushState(null, null, null);
41 value.pop();
40 value.pop();
43+ // TODO: disposer functon
@@ -48,11 +49,12 @@ export function HistoryProvider({ initialRoutes = [], children }) {
50// HOC version
51// HOC version
51−export const withHistory = Component => props => (
52+export const withHistory = Component =>
53+ forwardRef((props, ref) => (
52− <HistoryContext.Consumer>
54+ <HistoryContext.Consumer>
53− {history => <Component history={history} {...props} />}
55+ {history => <Component ref={ref} history={history} {...props} />}
54− </HistoryContext.Consumer>
56+ </HistoryContext.Consumer>
57// Hook version
59// Hook version
58export function useHistory() {
60export function useHistory() {