File tree 2 files changed +11
-32
lines changed
2 files changed +11
-32
lines changed Original file line number Diff line number Diff line change 1
- import * as React from 'react' ;
2
- import { Subtract } from 'utility-types' ;
1
+ import React from 'react' ;
3
2
4
3
const MISSING_ERROR = 'Error was swallowed during propagation.' ;
5
4
6
- // These props will be subtracted from base component props
7
- interface InjectedProps {
8
- onReset : ( ) => void ;
9
- }
10
-
11
- export const withErrorBoundary = < BaseProps extends InjectedProps > (
12
- _BaseComponent : React . ComponentType < BaseProps >
5
+ export const withErrorBoundary = < BaseProps extends { } > (
6
+ BaseComponent : React . ComponentType < BaseProps >
13
7
) => {
14
- // fix for TypeScript issues: https://github.com/piotrwitek/react-redux-typescript-guide/issues/111
15
- const BaseComponent = _BaseComponent as React . ComponentType < InjectedProps > ;
16
-
17
- type HocProps = Subtract < BaseProps , InjectedProps > & {
8
+ type HocProps = {
18
9
// here you can extend hoc with new props
19
10
} ;
20
11
type HocState = {
@@ -40,21 +31,12 @@ export const withErrorBoundary = <BaseProps extends InjectedProps>(
40
31
// TODO: send error report to service provider
41
32
} ;
42
33
43
- handleReset = ( ) => {
44
- this . setState ( { error : undefined } ) ;
45
- } ;
46
-
47
34
render ( ) {
48
35
const { children, ...restProps } = this . props ;
49
36
const { error } = this . state ;
50
37
51
38
if ( error ) {
52
- return (
53
- < BaseComponent
54
- onReset = { this . handleReset } // injected
55
- { ...restProps }
56
- />
57
- ) ;
39
+ return < BaseComponent { ...( restProps as BaseProps ) } /> ;
58
40
}
59
41
60
42
return children ;
Original file line number Diff line number Diff line change 1
- import * as React from 'react' ;
2
- import { Subtract } from 'utility-types' ;
1
+ import React from 'react' ;
2
+ import { Diff } from 'utility-types' ;
3
3
4
- // These props will be subtracted from base component props
4
+ // These props will be injected into the base component
5
5
interface InjectedProps {
6
6
count : number ;
7
7
onIncrement : ( ) => void ;
8
8
}
9
9
10
10
export const withState = < BaseProps extends InjectedProps > (
11
- _BaseComponent : React . ComponentType < BaseProps >
11
+ BaseComponent : React . ComponentType < BaseProps >
12
12
) => {
13
- // fix for TypeScript issues: https://github.com/piotrwitek/react-redux-typescript-guide/issues/111
14
- const BaseComponent = _BaseComponent as React . ComponentType < InjectedProps > ;
15
-
16
- type HocProps = Subtract < BaseProps , InjectedProps > & {
13
+ type HocProps = Diff < BaseProps , InjectedProps > & {
17
14
// here you can extend hoc with new props
18
15
initialCount ?: number ;
19
16
} ;
@@ -43,7 +40,7 @@ export const withState = <BaseProps extends InjectedProps>(
43
40
< BaseComponent
44
41
count = { count } // injected
45
42
onIncrement = { this . handleIncrement } // injected
46
- { ...restProps }
43
+ { ...( restProps as BaseProps ) }
47
44
/>
48
45
) ;
49
46
}
You can’t perform that action at this time.
0 commit comments