diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8e50044..ffe8b12 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,7 +2,7 @@ name: release on: push: tags: - - '*' + - "*" jobs: build: @@ -17,7 +17,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: 22.x - registry-url: 'https://registry.npmjs.org/' + registry-url: "https://registry.npmjs.org/" - run: npm ci - run: (cd example && npm install) - run: npm run build @@ -32,7 +32,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: './example/build' + path: "./example/build" - name: Deploy to GitHub Pages uses: actions/deploy-pages@v4 - uses: ncipollo/release-action@v1 diff --git a/README.md b/README.md index 41d05f6..5e98e5a 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,9 @@ npm install --save react-stomp-hooks See also [the supplied example project](https://svenkirschbaum.github.io/react-stomp-hooks/), and [its sourcecode](example/src/App.jsx). ```jsx -import React from 'react' +import React from "react"; -import { - StompSessionProvider, - useSubscription, -} from "react-stomp-hooks"; +import { StompSessionProvider, useSubscription } from "react-stomp-hooks"; const App = () => { return ( @@ -44,9 +41,7 @@ function SubscribingComponent() { //You can also supply an array as the first parameter, which will subscribe to all destinations in the array useSubscription("/topic/test", (message) => setLastMessage(message.body)); - return ( -
(WrappedComponent: React.ComponentType
) { const comp = (props: P) => { diff --git a/src/hoc/withSubscription.tsx b/src/hoc/withSubscription.tsx index 129d8c4..9084a96 100644 --- a/src/hoc/withSubscription.tsx +++ b/src/hoc/withSubscription.tsx @@ -1,15 +1,15 @@ -import { useRef } from 'react'; -import useSubscription from '../hooks/useSubscription'; -import { StompHeaders, IMessage } from '@stomp/stompjs'; +import { useRef } from "react"; +import useSubscription from "../hooks/useSubscription"; +import { StompHeaders, IMessage } from "@stomp/stompjs"; import { MessageReceiverInterface, - StompMessageReceiver -} from '../interfaces/StompMessageReceiver'; + StompMessageReceiver, +} from "../interfaces/StompMessageReceiver"; function withSubscription
( WrappedComponent: StompMessageReceiver
,
destinations: string | string[],
- headers: StompHeaders = {}
+ headers: StompHeaders = {},
) {
const comp = (props: P) => {
const ref = useRef (
(message: IMessage) => {
if (ref.current) ref.current.onMessage(message);
},
- headers
+ headers,
);
// @ts-expect-error - Ref type incompatible
diff --git a/src/hooks/useStompClient.tsx b/src/hooks/useStompClient.tsx
index 1732919..7391bb1 100644
--- a/src/hooks/useStompClient.tsx
+++ b/src/hooks/useStompClient.tsx
@@ -1,6 +1,6 @@
-import { useContext } from 'react';
-import StompContext from '../context/StompContext';
-import { StompSessionProviderContext } from '../interfaces/StompSessionProviderContext';
+import { useContext } from "react";
+import StompContext from "../context/StompContext";
+import { StompSessionProviderContext } from "../interfaces/StompSessionProviderContext";
/**
* Returns the Stomp Client from @stomp/stompjs
@@ -8,12 +8,12 @@ import { StompSessionProviderContext } from '../interfaces/StompSessionProviderC
*/
function useStompClient() {
const context = useContext = React.ComponentClass & {
- new (props: P, context?: unknown): React.Component & MessageReceiverInterface;
+ new (
+ props: P,
+ context?: unknown,
+ ): React.Component & MessageReceiverInterface;
};
diff --git a/src/interfaces/StompSessionProviderContext.ts b/src/interfaces/StompSessionProviderContext.ts
index b48b185..68a8cb7 100644
--- a/src/interfaces/StompSessionProviderContext.ts
+++ b/src/interfaces/StompSessionProviderContext.ts
@@ -1,10 +1,10 @@
-import { Client, messageCallbackType, StompHeaders } from '@stomp/stompjs';
+import { Client, messageCallbackType, StompHeaders } from "@stomp/stompjs";
export interface StompSessionProviderContext {
client?: Client;
subscribe: (
destination: string,
callback: messageCallbackType,
- headers?: StompHeaders
+ headers?: StompHeaders,
) => () => void;
}
diff --git a/src/interfaces/StompSessionProviderProps.ts b/src/interfaces/StompSessionProviderProps.ts
index c22eb22..9476d36 100644
--- a/src/interfaces/StompSessionProviderProps.ts
+++ b/src/interfaces/StompSessionProviderProps.ts
@@ -1,5 +1,5 @@
-import { StompConfig } from '@stomp/stompjs';
-import { ReactNode } from 'react';
+import { StompConfig } from "@stomp/stompjs";
+import { ReactNode } from "react";
export interface StompSessionProviderProps extends StompConfig {
url: string;
diff --git a/src/interfaces/StompSessionSubscription.ts b/src/interfaces/StompSessionSubscription.ts
index 406f0ad..d629554 100644
--- a/src/interfaces/StompSessionSubscription.ts
+++ b/src/interfaces/StompSessionSubscription.ts
@@ -1,8 +1,8 @@
import {
messageCallbackType,
StompHeaders,
- StompSubscription
-} from '@stomp/stompjs';
+ StompSubscription,
+} from "@stomp/stompjs";
export interface StompSessionSubscription {
destination: string;
diff --git a/src/mock/StompSessionProviderMock.tsx b/src/mock/StompSessionProviderMock.tsx
index 62a2f13..564aa7c 100644
--- a/src/mock/StompSessionProviderMock.tsx
+++ b/src/mock/StompSessionProviderMock.tsx
@@ -1,7 +1,7 @@
-import React from 'react';
-import StompContext from '../context/StompContext';
-import { subscribeMock } from './subscriptions';
-import { getMockClient } from './client';
+import React from "react";
+import StompContext from "../context/StompContext";
+import { subscribeMock } from "./subscriptions";
+import { getMockClient } from "./client";
/**
* A mock StompSessionProvider.
@@ -22,7 +22,7 @@ export default function StompSessionProviderMock(props: {
value={{
subscribe: subscribeMock,
// @ts-expect-error - Mock client is not a full client
- client: props.client ?? getMockClient()
+ client: props.client ?? getMockClient(),
}}
>
{props.children}
diff --git a/src/mock/client.tsx b/src/mock/client.tsx
index b5655a5..25e3ce5 100644
--- a/src/mock/client.tsx
+++ b/src/mock/client.tsx
@@ -1,4 +1,4 @@
-import { IPublishParams } from '@stomp/stompjs';
+import { IPublishParams } from "@stomp/stompjs";
export const messages = new Map