Get startedGet started with Notifications using Liveblocks and React

Liveblocks is a realtime collaboration infrastructure for building performant collaborative experiences. Follow the following steps to start adding notifications to your application using the hooks from @liveblocks/react and the components from @liveblocks/react-ui.

Quickstart

  1. Install Liveblocks

    Every package should use the same version.

    $npm install @liveblocks/client @liveblocks/react @liveblocks/react-ui
  2. Initialize the liveblocks.config.ts file

    We can use this file later to define types for our application.

    $npx create-liveblocks-app@latest --init --framework react
  3. Set up the Liveblocks client

    Liveblocks uses the concept of rooms, separate virtual spaces where collaborate, and to create a realtime experience, multiple users must be connected to the same room. Set up a Liveblocks client with LiveblocksProvider.

    App.tsx
    "use client";
    import { LiveblocksProvider } from "@liveblocks/react/suspense";import { Room } from "./Room";
    export default function App() { return ( <LiveblocksProvider publicApiKey={""}> <Room /> </LiveblocksProvider> );}
  4. Use the Liveblocks hooks and components

    Now that we’ve set up the provider, we can start using the Liveblocks hooks and components. We’ll add useInboxNotifications to get the current project’s notifications, then we’ll use InboxNotification and InboxNotificationList to render them.

    app/MyApp.tsx
    "use client";
    import { useInboxNotifications } from "@liveblocks/react/suspense";import { InboxNotification, InboxNotificationList,} from "@liveblocks/react-ui";
    export function CollaborativeApp() { const { inboxNotifications } = useInboxNotifications();
    return ( <InboxNotificationList> {inboxNotifications.map((inboxNotification) => ( <InboxNotification key={inboxNotification.id} inboxNotification={inboxNotification} /> ))} </InboxNotificationList> );}
  5. Import default styles

    The default components come with default styles, you can import them into the root of your app or directly into a CSS file with @import.

    import "@liveblocks/react-ui/styles.css";
  6. Next: authenticate and add your users

    Notifications is set up and working now, but each user is anonymous—the next step is to authenticate each user as they connect, and attach their name and avatar to their notifications.

    Add your users to Notifications

What to read next

Congratulations! You’ve set up the foundation to start building a notifications experience for your React application.


Examples using Notifications

We use cookies to collect data to improve your experience on our site. Read our Privacy Policy to learn more.