Initializing Services
In this section, we will show you how to initialize all avaiable Busy Hour Services in your React apps.
Initializing Activity Feeds
To use the activity feeds functionality, you need to initialize the activity feeds service first. To initialize the activity feeds service, you can use useInitActivityFeed
hook which is exported from the @busy-hour/react/hooks
package. The hook itself takes a boolean argument which determines if the service should be initialized or not.
Quick Example
import { useInitActivityFeed } from '@busy-hour/react/hooks';
export default function Main() {
// We recommend you to use a state as the argument instead of fixed value
// therefore the initialization will only happen once the service are initialized
useInitActivityFeed(true)
return <MainApp />
}
Initializing Messaging
To use the messaging functionality, you need to initialize two of the following services:
- Messaging
- Push Notifications
Initializing Messaging
To initialize only the messaging service without the notification, you can use the useInitMessaging
hook which is exported from the @busy-hour/react/hooks
package. The hook itself takes a boolean argument which determines if the service should be initialized or not.
Quick Example
import { useInitMessaging } from '@busy-hour/react/hooks';
export default function Main() {
// We recommend you to use a state as the argument instead of fixed value
// therefore the initialization will only happen once the service are initialized
useInitMessaging(true)
return <MainApp />
}
Initializing Push Notifications
To receive the new incoming messages as a notification, you need to initialize the notification services. To initialize it, you can use the useInitNotification
hook which is exported from the @busy-hour/react/hooks
package. Like the messaging service, the hook itself takes a boolean argument which determines if the service should be initialized or not.
When initializing the notification service, you will get an object as the return value which contains the workerRegister
and tokenListener
object. Both object will contains isInitialized
and isError
properties to determine if the service is initialized or not.
Quick Example
import { useInitNotification } from '@busy-hour/react/hooks';
export default function Main() {
// We recommend you to use a state as the argument instead of fixed value
// therefore the initialization will only happen once the service are initialized
const { workerRegister, tokenListener } = useInitNotification(true)
return <MainApp />
}