Skip to content

Commit 3a7c6da

Browse files
sophiebitsacdlite
authored andcommitted
Make effects actually work with memo
Bug fix.
1 parent 75a1c2e commit 3a7c6da

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,29 @@ describe('ReactHooks', () => {
12701270
]);
12711271
expect(ReactNoop.getChildren()).toEqual([]);
12721272
});
1273+
1274+
it('works with memo', () => {
1275+
function Counter({count}) {
1276+
useLayoutEffect(() => {
1277+
ReactNoop.yield('Mount: ' + count);
1278+
return () => ReactNoop.yield('Unmount: ' + count);
1279+
});
1280+
return <Text text={'Count: ' + count} />;
1281+
}
1282+
Counter = memo(Counter);
1283+
1284+
ReactNoop.render(<Counter count={0} />);
1285+
expect(ReactNoop.flush()).toEqual(['Count: 0', 'Mount: 0']);
1286+
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
1287+
1288+
ReactNoop.render(<Counter count={1} />);
1289+
expect(ReactNoop.flush()).toEqual(['Count: 1', 'Unmount: 0', 'Mount: 1']);
1290+
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
1291+
1292+
ReactNoop.render(null);
1293+
expect(ReactNoop.flush()).toEqual(['Unmount: 1']);
1294+
expect(ReactNoop.getChildren()).toEqual([]);
1295+
});
12731296
});
12741297

12751298
describe('useMutationEffect and useLayoutEffect', () => {

0 commit comments

Comments
 (0)