ts2fable icon indicating copy to clipboard operation
ts2fable copied to clipboard

Import React Components

Open 0x53A opened this issue 6 years ago • 1 comments

Currently react components are not really correctly imported.

Looking a bit through github I found https://github.com/fable-compiler/fable-react/issues/151#issuecomment-484612054

For example, react-popper-tooltip currently generates this


    type [<AllowNullLiteral>] IExports =
        abstract Tooltip: TooltipStatic

    type [<AllowNullLiteral>] Tooltip =
        inherit Component<TooltipProps>
        abstract componentDidMount: unit -> unit
        abstract componentDidUpdate: unit -> unit
        abstract componentWillUnmount: unit -> unit
        abstract render: unit -> JSX.Element

    type [<AllowNullLiteral>] TooltipStatic =
        [<Emit "new $0($1...)">] abstract Create: unit -> Tooltip
        abstract contextType: React.Context<TypeLiteral_01> with get, set

Better would probably be:

    type [<AllowNullLiteral>] IExports =
        abstract Tooltip: ReactElementType<TooltipProps>

Edit:

Hm, I don't think I can (easily) create an instance from an ReactElementType in F#, so maybe better generate this:

    type [<AllowNullLiteral>] IExports =
        abstract Tooltip: TooltipProps -> ReactElement

0x53A avatar Jun 29 '19 05:06 0x53A

SyntheticEvent was removed from Fable.React, in most cases MouseEvent should be used.

0x53A avatar Jul 01 '19 13:07 0x53A