Make effects actually work with memo
Bug fix.
Sophie Alpert committed
Oct 13, 2018 at 16:02 UTC
3a7c6da8d46763991d47ebf2198bc4e2fbfa0d9a
1 file changed
+23
packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js
+23
@@ -1270,6 +1270,29 @@ describe('ReactHooks', () => {
1270
]);
1271
expect(ReactNoop.getChildren()).toEqual([]);
1272
});
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
+ });
1296
});
1297
1298
describe('useMutationEffect and useLayoutEffect', () => {