Skip to content

Commit

Permalink
chore(client): Clean up React bindings (#1019)
Browse files Browse the repository at this point in the history
- Removed unused and undocumented `useRandom` hook which was originally
already removed in this PR
#585 but was added back
with another refactor
- Removed dependency on the injected electric client in `useLiveQuery`
  • Loading branch information
msfstef committed Mar 4, 2024
1 parent b65f3ed commit 31384af
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-camels-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electric-sql": patch
---

Remove unused React hook and clean up `useLiveQuery` hook
1 change: 0 additions & 1 deletion clients/typescript/src/frameworks/react/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as useConnectivityState } from './useConnectivityState'
export { default as useLiveQuery } from './useLiveQuery'
export { default as useRandom } from './useRandom'
7 changes: 2 additions & 5 deletions clients/typescript/src/frameworks/react/hooks/useLiveQuery.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useContext, useEffect, useState, useMemo, DependencyList } from 'react'
import { useEffect, useState, useMemo, DependencyList } from 'react'
import { hash } from 'ohash'

import { ElectricContext } from '../provider'
import {
LiveResultContext,
LiveResultUpdate,
Expand Down Expand Up @@ -92,16 +91,14 @@ function useLiveQueryWithQueryUpdates<Res>(
runQuery: LiveResultContext<Res>,
runQueryDependencies: DependencyList
): LiveResultUpdate<Res> {
const electric = useContext(ElectricContext)
const [resultData, setResultData] = useState<LiveResultUpdate<Res>>({})

// Once we have electric, we subscribe to the query results and
// update that subscription on any dependency change
useEffect(() => {
if (electric?.notifier === undefined) return
const unsubscribe = runQuery.subscribe(setResultData)
return unsubscribe
}, [electric?.notifier, ...runQueryDependencies])
}, runQueryDependencies)

return resultData
}
Expand Down
16 changes: 0 additions & 16 deletions clients/typescript/src/frameworks/react/hooks/useRandom.ts

This file was deleted.

0 comments on commit 31384af

Please sign in to comment.