All checks were successful
continuous-integration/drone/push Build is passing
37 lines
759 B
TypeScript
37 lines
759 B
TypeScript
import { act } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
|
|
export function renderHook<T>(useHook: () => T) {
|
|
let currentValue: T;
|
|
|
|
function TestComponent() {
|
|
currentValue = useHook();
|
|
return null;
|
|
}
|
|
|
|
const container = document.createElement('div');
|
|
const root = createRoot(container);
|
|
|
|
act(() => {
|
|
root.render(<TestComponent />);
|
|
});
|
|
|
|
return {
|
|
result: {
|
|
get current() {
|
|
return currentValue;
|
|
},
|
|
},
|
|
rerender() {
|
|
act(() => {
|
|
root.render(<TestComponent />);
|
|
});
|
|
},
|
|
unmount() {
|
|
act(() => {
|
|
root.unmount();
|
|
});
|
|
},
|
|
};
|
|
}
|