react-native-reusables icon indicating copy to clipboard operation
react-native-reusables copied to clipboard

[ BUG ] dropdown-menu TypeError

Open brunobely opened this issue 10 months ago • 2 comments

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 avatar Feb 04 '25 19:02 brunobely

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>

mrzachnugent avatar Feb 04 '25 21:02 mrzachnugent

@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}

heondo avatar Feb 16 '25 00:02 heondo

Fixed in the latest release

mrzachnugent avatar Aug 22 '25 17:08 mrzachnugent