Below is the code for HOC
const HOC = ({ component: Component }) => {
return () => {
const id = useQuery(query);
return (<div>
{!id ? ( <SomeOtherComponent prop1={'hello'} prop2={'world'} /> ) : ( <Component /> )}
</div>)
}
}
Below is the test to render HOC-
const myComponent = () => <div data-testid={'component-testid'}>ABC</div>;
const renderHOC = HOC({component: myComponent})();
const {getByTestId} = render(renderHOC);
expect(getByTestId('component-testid')).toBeInTheDocument();
Getting the error- Invalid hook call. React hooks must be called inside react functional component.
ComponentandSomeOtherComponentrespectively? Are they the same?const id = useQuery(query);out of thereturn () => {...}statement.