Created
July 14, 2017 15:05
-
-
Save mattiamanzati/7596e90d8a9214cea278f66c005602b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { inject } from "mobx-react"; | |
| import * as React from "react"; | |
| import { ObjectOmit } from "typelevel-ts"; // We <3 You gcanti | |
| function myInject<A, D extends keyof A>( | |
| mapStoreToProps: (store: any) => Pick<A, D>, | |
| component: React.ComponentType<A> | |
| ): React.SFC<ObjectOmit<A, D> & Partial<Pick<A, D>>>{ | |
| return inject(mapStoreToProps)(component as any) | |
| } | |
| const MyComp = ({ label, count }: { label: string; count: number }) => | |
| <p> | |
| {label} x {count} times! | |
| </p>; | |
| const MyCompConnected = myInject((store: any) => ({ count: 1 }), MyComp); | |
| const el1 = <MyCompConnected label="hello" />; | |
| const el2 = <MyCompConnected labels="hello" />; // error! :D | |
| const el3 = <MyCompConnected label="Hello world!" count={2} />; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment