on master help sign in
fix: implement forwardref api so refs work correctly
commit5e3bc8252e0c05d7d165f433a418db090e6924ac authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 11 Jun 2019, 12:24 (7 years ago) parent5a737fd
2 files changed+20−15
src/bridge/store/history.js+11−9 src/bridge/store/txnConfirmations.js+9−6
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';
22import { last, includes } from 'lodash';
33
44import { BRIDGE_ERROR } from '../lib/error';
@@ -29,10 +29,9 @@ export function HistoryProvider({ initialRoutes = [], children }) {
2929 };
3030
3131 // Scroll to top of page with each route transition.
32− useEffect(() => {
33− window.scrollTo(0, 0);
34− }, [history]);
32+ useEffect(() => window.scrollTo(0, 0), [history]);
3533
34+ // set up handlers
3635 useEffect(() => {
3736 window.history.pushState(null, null, null);
3837
@@ -40,6 +39,8 @@ export function HistoryProvider({ initialRoutes = [], children }) {
4039 window.history.pushState(null, null, null);
4140 value.pop();
4241 };
42+
43+ // TODO: disposer functon
4344 });
4445
4546 return (
@@ -48,11 +49,12 @@ export function HistoryProvider({ initialRoutes = [], children }) {
4849}
4950
5051// HOC version
51−export const withHistory = Component => props => (
52− <HistoryContext.Consumer>
53− {history => <Component history={history} {...props} />}
54− </HistoryContext.Consumer>
55−);
52+export const withHistory = Component =>
53+ forwardRef((props, ref) => (
54+ <HistoryContext.Consumer>
55+ {history => <Component ref={ref} history={history} {...props} />}
56+ </HistoryContext.Consumer>
57+ ));
5658
5759// Hook version
5860export 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';
22
33export const TxnConfirmationsContext = React.createContext(null);
44
@@ -24,11 +24,14 @@ export function TxnConfirmationsProvider({ children }) {
2424}
2525
2626// HOC version
27−export const withTxnConfirmations = Component => props => (
28− <TxnConfirmationsContext.Consumer>
29− {txnConfirmations => <Component {...txnConfirmations} {...props} />}
30− </TxnConfirmationsContext.Consumer>
31−);
27+export const withTxnConfirmations = Component =>
28+ forwardRef((props, ref) => (
29+ <TxnConfirmationsContext.Consumer>
30+ {txnConfirmations => (
31+ <Component ref={ref} {...txnConfirmations} {...props} />
32+ )}
33+ </TxnConfirmationsContext.Consumer>
34+ ));
3235
3336// Hook version
3437export function useTxnConfirmations() {