
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@trycourier/react-hooks
Advanced tools
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@trycourier/react-hooks
exist as a separate package so that you can build your own interface using our api and state management without having to install all the dependencies that @trycourier/react-inbox
or other react-dom
based packages include.
This also enables using this package with react-native
in a much simpler way.
As of 3.X we have started to use a new API for our inbox messages. The interface is slightly different which means interacting with the useInbox
hook will need to be updated to match the new interface.
interface ActionBlock {
type: "text";
text: string;
url: string;
}
interface OldMessage {
title: string;
body: string;
read?: boolean;
blocks: Array<TextBlock | ActionBlock>;
}
interface ActionElement {
type: "text";
content: string;
href: string;
}
interface NewMessage {
title: string;
preview: string;
read?: string;
actions: Array<ActionElement>;
}
This means if you were consuming const { messages } = useInbox
that the array of messages will now be different and will need to be updated.
The old versions had events like markRead(messageId, trackingId)
. The new version no longer requires passing a trackingId to track events.
interface IInboxActions {
markMessageArchived: (
messageId: string,
trackingId?: string
) => Promise<void>;
markMessageRead: (messageId: string, trackingId?: string) => Promise<void>;
markMessageUnread: (messageId: string, trackingId?: string) => Promise<void>;
markMessageOpened: (messageId: string, trackingId: string) => Promise<void>;
}
interface IInboxActions {
markMessageArchived: (messageId: string) => Promise<void>;
markMessageRead: (messageId: string) => Promise<void>;
markMessageUnread: (messageId: string) => Promise<void>;
markMessageOpened: (messageId: string) => Promise<void>;
}
Standard Inbox (useInbox
):
const inbox: IInbox & IInboxActions = useInbox();
interface ActionElement {
type: "text";
content: string;
href: string;
}
interface IInboxMessagePreview {
actions?: IActionElemental[];
archived?: string;
created: string;
data?: Record<string, any>;
messageId: string;
opened?: string;
preview?: string;
read?: string;
tags?: string[];
title?: string;
}
interface IInboxActions {
fetchMessages: (params?: IFetchMessagesParams) => void;
getUnreadMessageCount: (params?: IGetMessagesParams) => void;
init: (inbox: IInbox) => void;
markAllAsRead: (fromWS?: boolean) => void;
markMessageArchived: (messageId: string, fromWS?: boolean) => Promise<void>;
markMessageOpened: (messageId: string, fromWS?: boolean) => Promise<void>;
markMessageRead: (messageId: string, fromWS?: boolean) => Promise<void>;
markMessageUnread: (messageId: string, fromWS?: boolean) => Promise<void>;
newMessage: (transportMessage: IInboxMessagePreview) => void;
resetLastFetched: () => void;
setView: (view: string | "preferences") => void;
toggleInbox: (isOpen?: boolean) => void;
}
interface IInbox {
isLoading?: boolean;
isOpen?: boolean;
messages?: Array<IInboxMessagePreview>;
startCursor?: string;
unreadMessageCount?: number;
view?: string | "preferences";
}
Inbox supports a few different events that can be triggered on the client side.
These events are:
Some of these events are called automatically.
click through tracking
links. Click events will also automatically trigger a read
event.useInbox
Example)You can call events manually by importing the corresponding function from the react hook.
For Example:
import { CourierProvider } from "@trycourier/react-provider";
import { useInbox } from "@trycourier/react-hooks";
const MyInbox = () => {
const inbox = useInbox();
useEffect(() => {
inbox.fetchMessages();
}, []);
const handleReadMessage = (message) => (event) => {
event.preventDefault();
inbox.markMessageRead(message.messageId);
if (message.pinned) {
inbox.unpinMessage(message.messageId);
}
};
const handleUnreadMessage = (message) => (event) => {
event.preventDefault();
inbox.markMessageUnread(message.messageId);
};
const handleArchiveMessage = (message) => (event) => {
event.preventDefault();
inbox.markMessageArchived(message.messageId);
};
const handleArchiveMessage = (message) => (event) => {
event.preventDefault();
};
return (
<Container>
{inbox.messages.map((message) => {
return (
<Message message={message}>
{message.read ? (
<>
<button onClick={handleUnreadMessage(message)}>
Unread Me
</button>
<button onClick={handleArchiveMessage(message)}>
Archive Me
</button>
</>
) : (
<button onClick={handleReadMessage(message)}>Read Me</button>
)}
</Message>
);
})}
</Container>
);
};
const MyApp = () => {
return (
<CourierProvider userId="MY_USER_ID" clientKey="MY_CLIENT_KEY">
<MyInbox />
</CourierProvider>
);
};
FAQs
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
The npm package @trycourier/react-hooks receives a total of 28,035 weekly downloads. As such, @trycourier/react-hooks popularity was classified as popular.
We found that @trycourier/react-hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.