on master help sign in
fix: implement forwardref api so refs work correctly
5e3bc82Matt Condon (shrugs)
src/bridge/store/history.js+11−9
@@ -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';
3
3
4import { BRIDGE_ERROR } from '../lib/error';
4import { BRIDGE_ERROR } from '../lib/error';
@@ -29,10 +29,9 @@ export function HistoryProvider({ initialRoutes = [], children }) {
29 };
29 };
30
30
31 // Scroll to top of page with each route transition.
31 // Scroll to top of page with each route transition.
32− useEffect(() => {
33− window.scrollTo(0, 0);
32+ useEffect(() => window.scrollTo(0, 0), [history]);
34− }, [history]);
35
33
34+ // set up handlers
36 useEffect(() => {
35 useEffect(() => {
37 window.history.pushState(null, null, null);
36 window.history.pushState(null, null, null);
38
37
@@ -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();
42 };
41 };
42+
43+ // TODO: disposer functon
43 });
44 });
44
45
45 return (
46 return (
@@ -48,11 +49,12 @@ export function HistoryProvider({ initialRoutes = [], children }) {
48}
49}
49
50
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>
55−);
57+ ));
56
58
57// Hook version
59// Hook version
58export function useHistory() {
60export function useHistory() {
src/bridge/store/txnConfirmations.js+9−6
@@ -1,4 +1,4 @@
1−import React, { useContext, useState } from 'react';
1+import React, { forwardRef, useContext, useState } from 'react';
2
2
3export const TxnConfirmationsContext = React.createContext(null);
3export const TxnConfirmationsContext = React.createContext(null);
4
4
@@ -24,11 +24,14 @@ export function TxnConfirmationsProvider({ children }) {
24}
24}
25
25
26// HOC version
26// HOC version
27−export const withTxnConfirmations = Component => props => (
27+export const withTxnConfirmations = Component =>
28+ forwardRef((props, ref) => (
28− <TxnConfirmationsContext.Consumer>
29+ <TxnConfirmationsContext.Consumer>
30+ {txnConfirmations => (
29− {txnConfirmations => <Component {...txnConfirmations} {...props} />}
31+ <Component ref={ref} {...txnConfirmations} {...props} />
32+ )}
30− </TxnConfirmationsContext.Consumer>
33+ </TxnConfirmationsContext.Consumer>
31−);
34+ ));
32
35
33// Hook version
36// Hook version
34export function useTxnConfirmations() {
37export function useTxnConfirmations() {