Simple react native package for listening to date changes
source link: https://reactnativeexample.com/simple-react-native-package-for-listening-to-date-changes/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
React Native Midnight
Simple react native package for listening to date changes.
Installation
# with npm
npm install --save react-native-midnight
# with yarn
yarn add react-native-midnight
Midnight.addListener
The addListener function connects a function to a day change notification event.
This function then returns the reference to the listener. You can remove the listener by calling the remove
method on it.
import Midnight from 'react-native-midnight'
const App = () => {
React.useEffect(() => {
const listener = Midnight.addListener(() => {
Alert.alert('The day has changed')
})
return () => listener.remove()
}, [])
return <Text>App</Text>
}
useOnDayChange
Convenience hook that calls the passed function when the day changes
useOnDayChange((callback: () => void))
Note: Because useOnDayChange doesn't watch for dependency changes, the listener will be removed and re-added every time this hook is called. Creating your own effect inline with
Midnight.addListener
might be preferred if this is an issue.
GitHub
Subscribe to day change — Read More
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK