Skip to content

Instantly share code, notes, and snippets.

@shinchit
Created January 27, 2020 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinchit/1651fe3be2e5f0b888c0ed7661867c6a to your computer and use it in GitHub Desktop.
Save shinchit/1651fe3be2e5f0b888c0ed7661867c6a to your computer and use it in GitHub Desktop.
import React, { useEffect } from 'react';
import {
Button,
Icon,
} from 'native-base';
import { inject, useObserver } from 'mobx-react';
import withCommonProps from './withCommonProps'; // HOC ( Higher Order Component )
const SomeComponent = ({
dataStore, // inject from MobX
showError, // inject from HOC
}) => {
useEffect(() => {
// dataStore.fetch() method is loader to data which treat.
dataStore.fetch().catch((e) => showError(e));
}, [dataStore, showError]);
return useObserver(() => (
<Button
onPress={() => {
// dataStore.delete() method is a function to delete data which treat.
dataStore.delete().catch((e) => showError(e));
}}
>
<Icon active name="trash" />
</Button>
));
};
const component = withCommonProps(inject('dataStore')(SomeComponent));
export default component;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment