
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@knocklabs/react
Advanced tools
A set of React components to build notification experiences powered by Knock
A set of components for integrating Knock into a React application.
Using
@knocklabs/react-notification-feed
? See the migration guide for instructions on switching to@knocklabs/react
.
Note: these components are designed to be used via React for web only.
Via NPM:
npm install @knocklabs/react
Via Yarn:
yarn add @knocklabs/react
To configure the feed you will need:
You can integrate Knock into your app as follows:
import {
KnockFeedProvider,
KnockProvider,
NotificationFeedPopover,
NotificationIconButton,
} from "@knocklabs/react";
// Required CSS import, unless you're overriding the styling
import "@knocklabs/react/dist/index.css";
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}>
<div>
<NotificationIconButton
ref={notifButtonRef}
onClick={(e) => setIsVisible(!isVisible)}
/>
<NotificationFeedPopover
buttonRef={notifButtonRef}
isVisible={isVisible}
onClose={() => setIsVisible(false)}
/>
</div>
</KnockFeedProvider>
</KnockProvider>
);
};
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";
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 <span>Total unread: {metadata.unread_count}</span>;
};
FAQs
A set of React components to build notification experiences powered by Knock
We found that @knocklabs/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.