mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
Fix SSR useCallback in render phase (#14279)
This commit is contained in:
parent
0e9cb3f5d0
commit
ccb14e270c
|
|
@ -516,6 +516,19 @@ describe('ReactDOMServerHooks', () => {
|
|||
expect(domNode.tagName).toEqual('SPAN');
|
||||
expect(domNode.textContent).toEqual('Count: 0');
|
||||
});
|
||||
|
||||
itRenders('should support render time callbacks', async render => {
|
||||
function Counter(props) {
|
||||
const renderCount = useCallback(increment => {
|
||||
return 'Count: ' + (props.count + increment);
|
||||
});
|
||||
return <Text text={renderCount(3)} />;
|
||||
}
|
||||
const domNode = await render(<Counter count={2} />);
|
||||
expect(clearYields()).toEqual(['Count: 5']);
|
||||
expect(domNode.tagName).toEqual('SPAN');
|
||||
expect(domNode.textContent).toEqual('Count: 5');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useImperativeMethods', () => {
|
||||
|
|
|
|||
|
|
@ -341,6 +341,9 @@ function dispatchAction<A>(
|
|||
}
|
||||
|
||||
function noop(): void {}
|
||||
function identity(fn: Function): Function {
|
||||
return fn;
|
||||
}
|
||||
|
||||
export let currentThreadID: ThreadID = 0;
|
||||
|
||||
|
|
@ -357,10 +360,10 @@ export const Dispatcher = {
|
|||
useState,
|
||||
useMutationEffect,
|
||||
useLayoutEffect,
|
||||
// Callbacks are passed as they are in the server environment.
|
||||
useCallback: identity,
|
||||
// useImperativeMethods is not run in the server environment
|
||||
useImperativeMethods: noop,
|
||||
// Callbacks are not run in the server environment.
|
||||
useCallback: noop,
|
||||
// Effects are not run in the server environment.
|
||||
useEffect: noop,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user