Skip to content

Instantly share code, notes, and snippets.

@diasbruno
Created October 20, 2022 19:24
Show Gist options
  • Save diasbruno/a267b619a38affd5bd62aeed39b0a9cf to your computer and use it in GitHub Desktop.
Save diasbruno/a267b619a38affd5bd62aeed39b0a9cf to your computer and use it in GitHub Desktop.
dependency inversion with closures
export default function BaseComponent(apicall) {
return (props): React.FC => { // <<- this is the real renderable component
const { /* ... */ } = useUser(apicall);
return /* ... */
};
}
import BaseCompoment from 'basecomponent';
function mockGetUsers() {
return { /* stuff */ };
}
const RealImplementationOfComponent = BaseComponent(mockGetUsers);
describe('test bla bla bla...', () => {
render(RealImplementationOfComponent);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment