Created
April 29, 2019 05:41
-
-
Save choyongjoon/f24947c33c1a31df6f16fcfe3c7e865b to your computer and use it in GitHub Desktop.
MobX + React Hooks
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
const SomeComponent = inject("someStore")((props: SomeComponentProps) => { | |
// use hooks in here | |
const { someStore } = props; | |
const ref = useRef(null); | |
useEffect(() => { | |
someStore!.setRef(ref.current); | |
}, []); | |
return ( | |
<Observer> | |
{() => { | |
// use mobx store in here | |
const { someObservable, someComputed } = someStore!; | |
return ( | |
<div> | |
{someObservable} | |
{someComputed} | |
</div> | |
); | |
}} | |
</Observer> | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment