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

Forward refs for composer library #273

Open
vitonsky opened this issue Jan 21, 2024 · 1 comment
Open

Forward refs for composer library #273

vitonsky opened this issue Jan 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@vitonsky
Copy link
Owner

Forward refs for any compose primitives (like compose, composeU, withHOCConstructor, etc)

Examples

Example of current code:

import React from 'react';
import { cnIcon, IIconProps } from 'react-elegant-ui/esm/components/Icon/Icon';
import { withHOCConstructor } from 'react-elegant-ui/esm/lib/compose';

export type IIconModHasGlyph = {
	hasGlyph?: boolean;
};

export const withModHasGlyph = withHOCConstructor<IIconModHasGlyph, IIconProps>(
	{ matchProps: { hasGlyph: true }, matchOnlyProps: ['hasGlyph'] },
	(Component) => (props) =>
		(
			<Component
				{...props}
				className={cnIcon({ hasGlyph: true }, [props.className])}
			/>
		),
);

Example of possible solution

export const withModHasGlyph = withHOCConstructor<IIconModHasGlyph, IIconProps>(
	{ matchProps: { hasGlyph: true }, matchOnlyProps: ['hasGlyph'] },
	(Component) => (props, ref) =>
		(
			<Component
				ref={ref}
				{...props}
				className={cnIcon({ hasGlyph: true }, [props.className])}
			/>
		),
);
@vitonsky vitonsky added the enhancement New feature or request label Jan 21, 2024
@vitonsky
Copy link
Owner Author

Related to #166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant