-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add utils export and add some utils
- Loading branch information
Showing
12 changed files
with
1,255 additions
and
1,402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as withSafeSetState } from './withSafeSetState'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import hoistNonReactStatic from '../utils/hoistNonReactStatic'; | ||
|
||
function withSafeSetState() { | ||
return function enhanceWithSafeSetState<T extends typeof React.Component>(WrappedComponent: T) { | ||
let isMounted = false; | ||
const { componentDidMount, componentWillUnmount, setState } = WrappedComponent.prototype; | ||
|
||
WrappedComponent.prototype.componentDidMount = function () { | ||
isMounted = true; | ||
if (componentDidMount) { | ||
// @ts-ignore | ||
// eslint-disable-next-line prefer-rest-params | ||
componentDidMount.apply(this, arguments); | ||
} | ||
}; | ||
|
||
WrappedComponent.prototype.componentWillUnmount = function () { | ||
isMounted = false; | ||
if (componentWillUnmount) { | ||
// @ts-ignore | ||
// eslint-disable-next-line prefer-rest-params | ||
componentWillUnmount.apply(this, arguments); | ||
} | ||
}; | ||
|
||
WrappedComponent.prototype.setState = function () { | ||
if (isMounted && setState) { | ||
// @ts-ignore | ||
// eslint-disable-next-line prefer-rest-params | ||
setState.apply(this, arguments); | ||
} | ||
}; | ||
|
||
const WithSafeSetState = (props: any) => { | ||
return <WrappedComponent {...props} />; | ||
}; | ||
|
||
return hoistNonReactStatic(WithSafeSetState, WrappedComponent); | ||
}; | ||
} | ||
|
||
export default withSafeSetState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './components'; | ||
export * from './decorators'; | ||
export * from './hooks'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import hoistNonReactStatic from 'hoist-non-react-statics'; | ||
|
||
export default hoistNonReactStatic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export { default as getActionState } from './getActionState'; | ||
export { default as hoistNonReactStatic } from './hoistNonReactStatic'; | ||
export { default as isClassComponent } from './isClassComponent'; | ||
export { default as isDeepEqual } from './isDeepEqual'; | ||
export { default as isReactKey } from './isReactKey'; | ||
export { default as renderChildren } from './renderChildren'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.