mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Make effects actually work with memo
Bug fix.
This commit is contained in:
committed by
Andrew Clark
parent
75a1c2e72a
commit
3a7c6da8d4
@@ -1270,6 +1270,29 @@ describe('ReactHooks', () => {
|
||||
]);
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
});
|
||||
|
||||
it('works with memo', () => {
|
||||
function Counter({count}) {
|
||||
useLayoutEffect(() => {
|
||||
ReactNoop.yield('Mount: ' + count);
|
||||
return () => ReactNoop.yield('Unmount: ' + count);
|
||||
});
|
||||
return <Text text={'Count: ' + count} />;
|
||||
}
|
||||
Counter = memo(Counter);
|
||||
|
||||
ReactNoop.render(<Counter count={0} />);
|
||||
expect(ReactNoop.flush()).toEqual(['Count: 0', 'Mount: 0']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 0')]);
|
||||
|
||||
ReactNoop.render(<Counter count={1} />);
|
||||
expect(ReactNoop.flush()).toEqual(['Count: 1', 'Unmount: 0', 'Mount: 1']);
|
||||
expect(ReactNoop.getChildren()).toEqual([span('Count: 1')]);
|
||||
|
||||
ReactNoop.render(null);
|
||||
expect(ReactNoop.flush()).toEqual(['Unmount: 1']);
|
||||
expect(ReactNoop.getChildren()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('useMutationEffect and useLayoutEffect', () => {
|
||||
|
||||
Reference in New Issue
Block a user