Skip to content
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

Allow Guarded containers to be ReactNode, not only ComponentClass #15

Merged
merged 4 commits into from
Apr 1, 2019
Merged
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
8 changes: 4 additions & 4 deletions src/containers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export interface IDisabledContainerProps {
}

export interface IGuardedContainerProps {
disabledComponent: React.ComponentClass;
enabledComponent: React.ComponentClass;
disabledComponent: React.ReactNode;
enabledComponent: React.ReactNode;
isGuarded: boolean;
}

export function createDisabledContainer (WrappedComponent: React.ComponentClass<any>): React.ComponentClass {
export function createDisabledContainer (WrappedComponent: React.ComponentType<any>): React.ReactNode {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WrappedComponent: React.ReactNode here wouldn't work, it would trigger issues w/ constructor call signature.

@observer
class DisabledContainer extends Component<IDisabledContainerProps> {
public static displayName = `DisabledContainer(${getDisplayName(WrappedComponent)})`;
Expand Down Expand Up @@ -45,7 +45,7 @@ export function createDisabledContainer (WrappedComponent: React.ComponentClass<
export function createGuardedContainer ({ isGuarded, enabledComponent, disabledComponent }: IGuardedContainerProps): React.ComponentClass {
@observer
class GuardedContainer extends Component {
private readonly GuardedComponent: React.ComponentClass;
private readonly GuardedComponent: any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't optimal, but I spend a lot of time trying to figure that one out.
The issue is that we're setting that value after the constructor has triggered, so it would technically need to be :
private readonly GuardedComponent: React.ComponentClass<any> | {} | null | undefined;

Which felt ... messy || not efficient enough to justify it ?

Let me know what you think.

public static displayName = `GuardedContainer(${getDisplayName(enabledComponent)})`;

public constructor (props: any) {
Expand Down