Skip to content

Commit

Permalink
Merge pull request #1450 from ably/react-callbacks-error-message
Browse files Browse the repository at this point in the history
fix: throw descriptive error when callbacks used with react
  • Loading branch information
owenpearson authored Sep 25, 2023
2 parents ec653f1 + 9181064 commit fbcd191
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/platform/react-hooks/src/AblyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export const AblyProvider = ({ client, children, id = 'default' }: AblyProviderP
throw new Error('AblyProvider: the `client` prop is required');
}

if (!(client instanceof Ably.Realtime) && !client?.options?.promises) {
throw new Error('AblyProvider: the `client` prop must take an instance of Ably.Realtime.Promise');
}

const realtime = useMemo(() => client, [client]);

let context = getContext(id);
Expand Down
1 change: 1 addition & 0 deletions src/platform/react-hooks/src/fakes/ably.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class FakeAblySdk {
public clientId: string;
public channels: ClientChannelsCollection;
public connection: Connection;
public options = { promises: true };

constructor() {
this.clientId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
Expand Down

0 comments on commit fbcd191

Please sign in to comment.