-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Export useSlot
& useRenderProps
#6552
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
Comments
At least for |
export function callRenderProps<T extends object, R>(
value: R | ((renderProps: T) => R),
values: T
) {
if (typeof value === 'function') {
return (value as (renderProps: T) => R)(values);
}
return value;
} import { type CSSProperties, type ReactNode, useMemo } from 'react';
import { type RenderProps } from '../../types';
import { callRenderProps } from '../../utils';
type RenderPropsHookOptions<T extends object> = RenderProps<T> & {
values: T;
defaultChildren?: ReactNode;
defaultClassName?: string;
defaultStyle?: CSSProperties;
};
export function useRenderProps<T extends object>({
children: childrenProp,
className: classNameProp,
style: styleProp,
defaultChildren,
defaultClassName,
defaultStyle,
values,
}: RenderPropsHookOptions<T>) {
return useMemo(() => {
const children =
callRenderProps(childrenProp, { ...values, defaultChildren }) ??
defaultChildren;
const className =
callRenderProps(classNameProp, { ...values, defaultClassName }) ??
defaultClassName;
const style = callRenderProps(styleProp, { ...values, defaultStyle });
return {
...(children != null ? { children } : {}),
...(className ? { className } : {}),
...(style || defaultStyle ? { style: { ...defaultStyle, ...style } } : {}),
};
}, [
childrenProp,
classNameProp,
styleProp,
defaultChildren,
defaultClassName,
defaultStyle,
values,
]);
} |
Why is |
#8013 implements it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Provide a general summary of the feature here
The
useSlot
&useRenderProps
hooks are very useful utilities within theProvider
suite. Since we're already able to utilizeProvider
and the many different component contexts (as well as our own), it would be nice to have full access to related utilities🤔 Expected Behavior?
useSlot
&useRenderProps
are exported byreact-aria-components
😯 Current Behavior
Not currently exported
💁 Possible Solution
No response
🔦 Context
I'm currently utilizing
useSlot
to determine if a slot has been implemented or not, which allows for a flag to be provided for logic / styling branchingI'm expecting to have to implement new custom components that will want to implement their own render props
💻 Examples
No response
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
The text was updated successfully, but these errors were encountered: