react-native-midnight
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i react-native-midnight

Weekly Downloads

637

Version

1.0.2

License

MIT

Unpacked Size

98.1 kB

Total Files

37

Last publish

Collaborators

  • donovanhiland