Created
October 20, 2022 19:24
-
-
Save diasbruno/a267b619a38affd5bd62aeed39b0a9cf to your computer and use it in GitHub Desktop.
dependency inversion with closures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function BaseComponent(apicall) { | |
return (props): React.FC => { // <<- this is the real renderable component | |
const { /* ... */ } = useUser(apicall); | |
return /* ... */ | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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