Skip to content

hoist static members in asRadioGroupChild HOC #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions generatedTypes/components/radioButton/RadioButton.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { TextStyle, ImageStyle } from 'react-native';
import { TextStyle, ImageSourcePropType, ImageStyle } from 'react-native';
interface RadioButtonPropTypes {
/**
* The identifier value of the radio button. must be different than other RadioButtons in the same group
Expand Down Expand Up @@ -40,7 +40,7 @@ interface RadioButtonPropTypes {
/**
* Icon image source
*/
iconSource?: object | number;
iconSource?: ImageSourcePropType;
/**
* Icon image style
*/
Expand Down
2 changes: 1 addition & 1 deletion src/components/radioButton/RadioButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,4 @@ function createStyles(props: Props) {
});
}

export default asRadioGroupChild(asBaseComponent<RadioButtonPropTypes>(forwardRef(RadioButton)));
export default asBaseComponent<RadioButtonPropTypes>(forwardRef(asRadioGroupChild(RadioButton)));
7 changes: 7 additions & 0 deletions src/components/radioButton/asRadioGroupChild.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, {Component} from 'react';
// @ts-ignore
import hoistStatics from 'hoist-non-react-statics';
import RadioGroupContext from './RadioGroupContext';

interface RadioGroupChildPropTypes {
Expand All @@ -16,6 +18,8 @@ type PropTypes = RadioGroupChildPropTypes;

export default function asRadioGroupChild(WrappedComponent: React.ComponentType<any>) {
class RadioGroupChild extends Component<PropTypes> {
static displayName: string | undefined;

render() {
const {value: buttonValue, selected} = this.props;
return (
Expand All @@ -33,5 +37,8 @@ export default function asRadioGroupChild(WrappedComponent: React.ComponentType<
}
}

hoistStatics(RadioGroupChild, WrappedComponent);
RadioGroupChild.displayName = WrappedComponent.displayName;

return RadioGroupChild as any;
}