xmtp / xmtp-web

XMTP web SDKs and examples, including a React SDK and quickstart example app

Home Page:https://xmtp.github.io/xmtp-web/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`message.contentType` is a string but `codecFor` expects an object

fabriguespe opened this issue · comments

Describe the bug

In the reactSDK (as well as in the JS SDK) codecFor expects a contenType object.

/**
 * Find a matching codec for a given `ContentTypeId` from the
 * client's codec registry
 */
codecFor(contentType: ContentTypeId): ContentCodec<any> | undefined;

Yet in the reactSDK the message.contentType returns a string, making codecFor return undefined

This is how it looks in react
CleanShot 2024-02-28 at 15 11 34@2x

This is how it looks in js
CleanShot 2024-02-28 at 14 57 13@2x

Expected behavior

No response

Steps to reproduce the bug

No response

thanks for reporting this! yes, in the React SDK, we use/store contentType as a string. to convert back to an object for use in codecFor, use the ContentTypeId.fromString static method.

const contentType = ContentTypeId.fromString(message.contentType);
const codec = xmtpClient.codecFor(contentType);

Thks! Updated the docs snippet
xmtp/xmtp-dot-org#680