diff --git a/ppx/src/reactjs_jsx_ppx.ml b/ppx/src/reactjs_jsx_ppx.ml index 206f8982a..de1700cfd 100644 --- a/ppx/src/reactjs_jsx_ppx.ml +++ b/ppx/src/reactjs_jsx_ppx.ml @@ -795,6 +795,16 @@ let jsxMapper = (_wrapperExpression, [ (Nolabel, innerFunctionExpression) ]); } -> spelunkForFunExpression innerFunctionExpression + (* let make = React.memoCustomCompareProps( + (~prop) => ..., + (prevProps, nextProps) => false + ) *) + | { + pexp_desc = + Pexp_apply + (_wrapperExpression, [ (Nolabel, innerFunctionExpression); _ ]); + } -> + spelunkForFunExpression innerFunctionExpression | { pexp_desc = Pexp_sequence (_wrapperExpression, innerFunctionExpression); @@ -805,7 +815,7 @@ let jsxMapper = (Invalid_argument "react.component calls can only be on function \ definitions or component wrappers (forwardRef, \ - memo).") + memo or memoCustomCompareProps).") [@@raises Invalid_argument] in spelunkForFunExpression expression diff --git a/ppx/test/input.re b/ppx/test/input.re index da53f594e..5a293ca3f 100644 --- a/ppx/test/input.re +++ b/ppx/test/input.re @@ -108,22 +108,22 @@ module Upper_case_with_fragment_as_root = { ; }; -/* module Using_React_memo = { - [@react.component] - let make = - React.memo((~a) => -
{Printf.sprintf("`a` is %s", a) |> React.string}
- ); - }; */ - -/* module Using_memo_custom_compare_Props = { - [@react.component] - let make = - React.memo( - (~a) =>
{Printf.sprintf("`a` is %d", a) |> React.string}
, - (prevPros, nextProps) => false, - ); - }; */ +module Using_React_memo = { + [@react.component] + let make = + React.memo((~a) => +
{Printf.sprintf("`a` is %s", a) |> React.string}
+ ); +}; + +module Using_memo_custom_compare_Props = { + [@react.component] + let make = + React.memoCustomCompareProps( + (~a) =>
{Printf.sprintf("`a` is %d", a) |> React.string}
, + (prevPros, nextProps) => false, + ); +}; module Forward_Ref = { [@react.component] diff --git a/ppx/test/output.expected b/ppx/test/output.expected index ff730bf2e..a746abb4b 100644 --- a/ppx/test/output.expected +++ b/ppx/test/output.expected @@ -202,6 +202,38 @@ module Upper_case_with_fragment_as_root = (Props : < name: 'name option > Js.t) = make ?name:(Props ## name) in Generated$Upper_case_with_fragment_as_root end +module Using_React_memo = + struct + external makeProps : + a:'a -> ?key:string -> unit -> < a: 'a > Js.t = ""[@@bs.obj ] + let make = + ((fun ~a -> + ReactDOM.jsx "div" + (((ReactDOM.domProps)[@merlin.hide ]) + ~children:((Printf.sprintf "`a` is %s" a) |> React.string) ())) + [@warning "-16"]) + let make = + React.memo + (let Generated$Using_React_memo (Props : < a: 'a > Js.t) = + make ~a:(Props ## a) in + Generated$Using_React_memo) + end +module Using_memo_custom_compare_Props = + struct + external makeProps : + a:'a -> ?key:string -> unit -> < a: 'a > Js.t = ""[@@bs.obj ] + let make = + React.memoCustomCompareProps + (fun ~a -> + ReactDOM.jsx "div" + (((ReactDOM.domProps)[@merlin.hide ]) + ~children:((Printf.sprintf "`a` is %d" a) |> React.string) ())) + (fun prevPros -> fun nextProps -> false) + let make = + let Generated$Using_memo_custom_compare_Props + (Props : < a: 'a > Js.t) = make ~a:(Props ## a) in + Generated$Using_memo_custom_compare_Props + end module Forward_Ref = struct external makeProps :