pmndrs / react-three-flex

💪📦 Flexbox for react-three-fiber
MIT License
1.65k stars 42 forks source link

Exposed FlexProps so it can be used to type components that wrap <Flex> #46

Closed saitonakamura closed 3 years ago

giulioz commented 3 years ago

Can you provide an use case?

saitonakamura commented 3 years ago

I have a component that draws a flex list of items and I want to allow to override or define certain properties (or all of them) on this component that has Flex as a root and I don't want to copy paste the typings of this props

For instance

export const List = ({
  items,
  size = [12, 7, 0.1],
  ...rest
}: {
  items: Type[];
} & Pick<FlexProps, 'position' | 'size'>) => (
  <Flex {...rest} size={size} flexDirection="column" flexWrap="wrap">
    {items.map((b) => (...))}
  </Flex>
);

Or it could be something like Partial<FlexProps>

Currently it still can be achieved through typescript debauchery, but having a FlexProps would be better

type ExtractProps<T extends (props: any) => JSX.Element> = T extends (
  props: infer R
) => JSX.Element
  ? R
  : never;

type FlexProps = ExtractProps<typeof Flex>

As a side note, library's already exposing R3FlexProps

giulioz commented 3 years ago

Yeah you are right, LGTM then :)