File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -359,4 +359,54 @@ describe("React", () => {
359359 /* We catch the exception here to not populate the error to the toplevel */
360360 ()
361361 };
362+
363+ test(
364+ "Memo and normal components rendering with equal and different props" , () => {
365+ let container = getContainer(container);
366+ let root = ReactDOM . Client . createRoot(container);
367+
368+ module Normal = {
369+ let renders = ref (0 );
370+
371+ [@ react . component ]
372+ let make = (~a) => {
373+ renders := renders^ + 1 ;
374+ <div > {Printf . sprintf("`a` is % s " , a) |> React . string} </div >;
375+ };
376+ };
377+
378+ module Memo = {
379+ let renders = ref (0 );
380+
381+ [@ react . component ]
382+ let make =
383+ React . memo((~a) => {
384+ renders := renders^ + 1 ;
385+ <div > {Printf . sprintf("`a` is % s " , a) |> React . string} </div >;
386+ });
387+ };
388+
389+ act(() => {
390+ ReactDOM . Client . render(
391+ root,
392+ <div > <Normal a= "a" /> <Memo a= "a" /> </div >,
393+ )
394+ });
395+ act(() => {
396+ ReactDOM . Client . render(
397+ root,
398+ <div > <Normal a= "a" /> <Memo a= "a" /> </div >,
399+ )
400+ });
401+ act(() => {
402+ ReactDOM . Client . render(
403+ root,
404+ <div > <Normal a= "b" /> <Memo a= "b" /> </div >,
405+ )
406+ });
407+
408+ expect(Normal . renders^ )-> toBe(3 );
409+
410+ expect(Memo . renders^ )-> toBe(2 );
411+ });
362412});
You can’t perform that action at this time.
0 commit comments