Skip to content

Instantly share code, notes, and snippets.

@choyongjoon
Created April 29, 2019 05:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choyongjoon/f24947c33c1a31df6f16fcfe3c7e865b to your computer and use it in GitHub Desktop.
Save choyongjoon/f24947c33c1a31df6f16fcfe3c7e865b to your computer and use it in GitHub Desktop.
MobX + React Hooks
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