mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 17:31:25 +08:00
d689c7b855
* feat: remove locale-provider * chore: fix lint * Empty-Commit * test: remove test * Revert "test: remove test" This reverts commit 4f6b59883f6bf078f21a10898ef913c9e2adb913. * chore: 阶段性兼容 * fix lint * fix: fix lint * fix: add index * docs: update docs * docs: update * docs: update * docs: update
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import React, { memo, useContext } from 'react';
|
|
import { fireEvent, pureRender } from '../../../tests/utils';
|
|
import LocaleProvider from '../../locale';
|
|
import LocaleContext from '../../locale/context';
|
|
|
|
let innerCount = 0;
|
|
let outerCount = 0;
|
|
|
|
const handleClick = () => {
|
|
outerCount++;
|
|
};
|
|
|
|
// we use'memo' here in order to only render inner component while context changed.
|
|
const CacheInner: React.FC = memo(() => {
|
|
innerCount++;
|
|
// subscribe locale context
|
|
useContext(LocaleContext);
|
|
return null;
|
|
});
|
|
|
|
const CacheOuter: React.FC = memo(() => (
|
|
<>
|
|
<button type="button" onClick={handleClick} id="parent_btn">
|
|
Click
|
|
</button>
|
|
<LocaleProvider locale={{ locale: 'locale' }}>
|
|
<CacheInner />
|
|
</LocaleProvider>
|
|
</>
|
|
));
|
|
|
|
it("Rendering on LocaleProvider won't trigger rendering on child component.", () => {
|
|
const { container, unmount } = pureRender(<CacheOuter />);
|
|
expect(outerCount).toBe(0);
|
|
expect(innerCount).toBe(1);
|
|
fireEvent.click(container.querySelector('#parent_btn')!);
|
|
expect(outerCount).toBe(1);
|
|
expect(innerCount).toBe(1);
|
|
unmount();
|
|
});
|