Created
January 27, 2020 23:16
-
-
Save shinchit/1651fe3be2e5f0b888c0ed7661867c6a to your computer and use it in GitHub Desktop.
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 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