Skip to content

[ BUG ] dropdown-menu TypeError #336

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

Open
brunobely opened this issue Feb 4, 2025 · 2 comments
Open

[ BUG ] dropdown-menu TypeError #336

brunobely opened this issue Feb 4, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@brunobely
Copy link

Using @rn-primitives/dropdown-menu^1.1.0, the following TS error pops up in dropdown-menu.tsx:

Type '{ children: ReactNode | ((state: PressableStateCallbackType) => ReactNode); }' is not assignable to type '{ children?: ReactNode; }'.
  Types of property 'children' are incompatible.
    Type 'ReactNode | ((state: PressableStateCallbackType) => ReactNode)' is not assignable to type 'ReactNode'.
      Type '(state: PressableStateCallbackType) => ReactNode' is not assignable to type 'ReactNode'.ts(2322)
@brunobely brunobely added the bug Something isn't working label Feb 4, 2025
@mrzachnugent
Copy link
Owner

Hey @brunobely, I'm working on rn-primitives v2 and I'm going to include a helper function for pressable children which can be React.ReactNode | ((state: PressableStateCallbackType) => ReactNode);.

You can use the following helper function or for the children prop to be of type React.ReactNode

// helper function
function renderPressableChildren(
  children: PressableProps['children'],
  render: (children: React.ReactNode) => React.ReactNode
) {
  return typeof children === 'function'
    ? (state: PressableStateCallbackType) => render(children(state))
    : render(children);
}

// usage example
<AccordionPrimitive.Trigger
  ref={ref}
  {...props}
>
  {renderPressableChildren(childrenProp, (children) => {
    return (
      <>
        {children}
        <ChevronDown size={18} />
      </>
    );
  })}
</AccordionPrimitive.Trigger>

@heondo
Copy link

heondo commented Feb 16, 2025

@mrzachnugent i'm trying this without much luck and what childrenProp should be isn't very clear. Honestly had better luck just ignoring the function call because hovered/pressed state isn't readily available

{typeof children !== "function" && children}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants