Skip to content

Commit 0e36a12

Browse files
Keep str as ofString alias and check options
1 parent 6ee8636 commit 0e36a12

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Fable.React/Fable.Helpers.React.fs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,21 +616,24 @@ let inline ofFunction<[<Pojo>]'P> (f: 'P -> ReactElement) (props: 'P) (children:
616616
createElement(f, props, children)
617617

618618
/// Instantiate an imported React component. The first two arguments must be string literals, "default" can be used for the first one.
619-
/// Example: `ofImported "Map" "leaflet" { x = 10; y = 50 } []`
620-
let inline ofImported<[<Pojo>]'P> (importMember: string) (importPath: string) (props: 'P) (children: ReactElement list): ReactElement =
619+
/// Example: `ofImport "Map" "leaflet" { x = 10; y = 50 } []`
620+
let inline ofImport<[<Pojo>]'P> (importMember: string) (importPath: string) (props: 'P) (children: ReactElement list): ReactElement =
621621
createElement(import importMember importPath, props, children)
622622

623-
/// OBSOLETE: Use `ofString`
624-
[<System.Obsolete("Use ofString")>]
623+
/// Alias of `ofString`
625624
let inline str (s: string): ReactElement = unbox s
626-
/// OBSOLETE: Use `ofOption`
627-
[<System.Obsolete("Use ofOption")>]
628-
let inline opt (o: ReactElement option): ReactElement = unbox o
629625

630626
/// Cast a string to a React element (erased in runtime)
631627
let inline ofString (s: string): ReactElement = unbox s
628+
629+
/// OBSOLETE: Use `ofOption`
630+
[<System.Obsolete("Use ofOption")>]
631+
let inline opt (o: ReactElement option): ReactElement =
632+
match o with Some o -> o | None -> null
633+
632634
/// Cast an option value to a React element (erased in runtime)
633-
let inline ofOption (o: ReactElement option): ReactElement = unbox o
635+
let inline ofOption (o: ReactElement option): ReactElement =
636+
match o with Some o -> o | None -> null // Option.toObj(o)
634637

635638
/// Cast an int to a React element (erased in runtime)
636639
let inline ofInt (i: int): ReactElement = unbox i

src/Fable.React/Fable.Import.React.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module React =
99
type ReactType =
1010
U3<string, ComponentClass<obj>, StatelessComponent<obj>>
1111

12-
and ReactElement =
12+
and [<AllowNullLiteral>] ReactElement =
1313
interface end
1414

1515
and ClassicElement<'P> =

0 commit comments

Comments
 (0)