Skip to content

Commit 4a0a4c5

Browse files
vbfoxalfonsogarciacaro
authored andcommitted
Always name memo and memoWith
1 parent 60eef88 commit 4a0a4c5

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,10 @@ module ReactElementType =
901901

902902
type PropsEqualityComparison<'props> = 'props -> 'props -> bool
903903

904+
[<Import("memo", from="react")>]
905+
let private reactMemo<'props> (render: 'props -> ReactElement) : ReactComponentType<'props> =
906+
jsNative
907+
904908
/// React.memo is a higher order component. It’s similar to React.PureComponent but for function components instead of
905909
/// classes.
906910
///
@@ -910,8 +914,12 @@ type PropsEqualityComparison<'props> = 'props -> 'props -> bool
910914
///
911915
/// By default it will only shallowly compare complex objects in the props object. If you want control over the
912916
/// comparison, you can use `memoWith`.
917+
let memo<'props> (name: string) (render: 'props -> ReactElement) : ReactComponentType<'props> =
918+
render?displayName <- name
919+
reactMemo(render)
920+
913921
[<Import("memo", from="react")>]
914-
let memo<'props> (render: 'props -> ReactElement) : ReactComponentType<'props> =
922+
let private reactMemoWith<'props> (render: 'props -> ReactElement, areEqual: PropsEqualityComparison<'props>) : ReactComponentType<'props> =
915923
jsNative
916924

917925
/// React.memo is a higher order component. It’s similar to React.PureComponent but for function components instead of
@@ -922,10 +930,10 @@ let memo<'props> (render: 'props -> ReactElement) : ReactComponentType<'props> =
922930
/// component, and reuse the last rendered result.
923931
///
924932
/// This version allow you to control the comparison used instead of the default shallow one by provide a custom
925-
/// comparison function as the second argument.
926-
[<Import("memo", from="react")>]
927-
let memoWith<'props> (render: 'props -> ReactElement, areEqual: PropsEqualityComparison<'props>) : ReactComponentType<'props> =
928-
jsNative
933+
/// comparison function.
934+
let memoWith<'props> (name: string) (areEqual: PropsEqualityComparison<'props>) (render: 'props -> ReactElement) : ReactComponentType<'props> =
935+
render?displayName <- name
936+
reactMemoWith(render, areEqual)
929937

930938
/// Create a ReactElement to be rendered from an element type, props and children
931939
let inline ofElementType<'props> (comp: ReactElementType<'props>) (props: 'props) (children: ReactElement seq): ReactElement =

0 commit comments

Comments
 (0)