Skip to content

syngenta-digital/mobile-reactnative-midnight

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Native Midnight

Simple react native package for listening to date changes

CI status codecov semantic-release NPM version NPM downloads

Installation

# with npm
npm install --save react-native-midnight

# with yarn
yarn add react-native-midnight

API

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.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

About

Subscribe to day change and hour change

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 28.1%
  • TypeScript 17.1%
  • Objective-C 15.9%
  • Kotlin 14.3%
  • JavaScript 11.4%
  • Swift 7.4%
  • Other 5.8%