0.6.21 • Published 6 months ago

@knocklabs/react-native v0.6.21

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Knock React Native SDK

A set of components for integrating Knock in-app notifications into a React Native application.

Full documentation

Installation

Via NPM:

npm install @knocklabs/react-native

Via Yarn:

yarn add @knocklabs/react-native

Configuration

To configure the feed you will need:

  1. A public API key (found in the Knock dashboard)
  2. A user ID, and optionally an auth token for production environments
  3. If integrating an in-app feed, a feed channel ID (found in the Knock dashboard)

Usage

You can integrate the feed into your app as follows:

import {
  KnockProvider,
  KnockFeedProvider,
  NotificationFeedContainer,
} from "@knocklabs/react-native";

const YourAppLayout = () => {
  const [isVisible, setIsVisible] = useState(false);
  const notifButtonRef = useRef(null);

  return (
    <KnockProvider apiKey={process.env.KNOCK_PUBLIC_API_KEY} userId={userId}>
      {/* Optionally, use the KnockFeedProvider to connect an in-app feed */}
      <KnockFeedProvider feedId={process.env.KNOCK_FEED_ID}>
        <NotificationFeedContainer>
          <Text>Notifications go in here!</Text>
        </NotificationFeedContainer>
      </KnockFeedProvider>
    </KnockProvider>
  );
};

Headless usage

Alternatively, if you don't want to use our components you can render the feed in a headless mode using our hooks:

import {
  useAuthenticatedKnockClient,
  useNotifications,
} from "@knocklabs/react-native";
import create from "zustand";

const YourAppLayout = () => {
  const knockClient = useAuthenticatedKnockClient(
    process.env.KNOCK_PUBLIC_API_KEY,
    currentUser.id,
  );

  const notificationFeed = useNotifications(
    knockClient,
    process.env.KNOCK_FEED_ID,
  );

  const useNotificationStore = create(notificationFeed.store);
  const { metadata } = useNotificationStore();

  useEffect(() => {
    notificationFeed.fetch();
  }, [notificationFeed]);

  return <Text>Total unread: {metadata.unread_count}</Text>;
};

Related links

0.6.21

6 months ago

0.5.10

10 months ago

0.6.20

6 months ago

0.5.11

9 months ago

0.6.7

8 months ago

0.6.6

8 months ago

0.6.9

8 months ago

0.6.8

8 months ago

0.5.12

9 months ago

0.6.0-rc.0

10 months ago

0.6.10

8 months ago

0.6.12

7 months ago

0.6.11

8 months ago

0.6.0-rc.2.0

9 months ago

0.6.18

7 months ago

0.6.17

7 months ago

0.6.19

6 months ago

0.6.14

7 months ago

0.6.13

7 months ago

0.6.16

7 months ago

0.6.15

7 months ago

0.5.2-rc.0

1 year ago

0.5.4

11 months ago

0.5.2-rc-5.0

11 months ago

0.5.3

12 months ago

0.5.6

11 months ago

0.5.5

11 months ago

0.5.2-rc-1.0

1 year ago

0.5.2

1 year ago

0.5.8

10 months ago

0.5.7

11 months ago

0.6.1-rc.0

9 months ago

0.5.9

10 months ago

0.5.3-rc.0

1 year ago

0.6.0-rc.1.0

10 months ago

0.6.0-rc.3.0

9 months ago

0.6.3

8 months ago

0.5.2-rc-4.0

11 months ago

0.6.2

9 months ago

0.6.5

8 months ago

0.6.4

8 months ago

0.6.1

9 months ago

0.5.2-rc-2.0

11 months ago

0.6.0

9 months ago

0.5.1-rc.0

1 year ago

0.5.0

1 year ago

0.5.1

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.7

1 year ago

0.2.6

2 years ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0-rc1

2 years ago

0.1.0-rc0

2 years ago