Skip to content

Commit

Permalink
feat(useWebSocket): allow undefined ref for url (#2473)
Browse files Browse the repository at this point in the history
* feat(useWebSocket): allow undefined ref for url

* docs(useWebSocket): update outdated type declarations
  • Loading branch information
ferferga committed Jan 29, 2023
1 parent 902b3cc commit 1392410
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/useWebSocket/index.md
Expand Up @@ -174,7 +174,7 @@ export interface WebSocketResult<T> {
* @param url
*/
export declare function useWebSocket<Data = any>(
url: string,
url: MaybeComputedRef<string | URL | undefined>,
options?: WebSocketOptions
): WebSocketResult<Data>
```
Expand Down
4 changes: 2 additions & 2 deletions packages/core/useWebSocket/index.ts
Expand Up @@ -143,7 +143,7 @@ function resolveNestedOptions<T>(options: T | true): T {
* @param url
*/
export function useWebSocket<Data = any>(
url: MaybeComputedRef<string | URL>,
url: MaybeComputedRef<string | URL | undefined>,
options: UseWebSocketOptions = {},
): UseWebSocketReturn<Data> {
const {
Expand Down Expand Up @@ -205,7 +205,7 @@ export function useWebSocket<Data = any>(
}

const _init = () => {
if (explicitlyClosed)
if (explicitlyClosed || typeof urlRef.value === 'undefined')
return

const ws = new WebSocket(urlRef.value, protocols)
Expand Down

0 comments on commit 1392410

Please sign in to comment.