Skip to content

Commit

Permalink
feat: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-lindgren committed Jan 23, 2025
1 parent 99f60da commit 3ffec9e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
13 changes: 1 addition & 12 deletions examples/immer-yjs-react/src/ContextState.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bind, Binder } from 'immer-yjs'
import * as Y from 'yjs'
import { useBinder, useSelection } from './immer-yjs-react'
import { useSelection } from './immer-yjs-react'
import { createContext, useContext } from 'react'
import { AppState } from './AppState'

Expand All @@ -13,17 +13,6 @@ const getMap = (doc: Y.Doc, key: string) => doc.getMap(key)
const BinderContext = createContext<Binder<AppState>>(bind(getMap(new Y.Doc(), 'state')))

export const ContextState = () => {
const doc = new Y.Doc()
const rootProp = doc.getMap('state')
const store = useBinder<AppState>(rootProp)
return (
<BinderContext.Provider value={store}>
<AppWithContext />
</BinderContext.Provider>
)
}

const AppWithContext = () => {
const binder = useContext(BinderContext)
const resetState = () => {
binder.update(() => ({
Expand Down
2 changes: 1 addition & 1 deletion examples/immer-yjs-react/src/immer-yjs-react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const useBinder = <T extends Snapshot = Snapshot>(source: Y.Map<unknown>
const binder = bind<T>(source)
useEffect(() => {
return binder.unbind
}, [])
}, [binder.unbind])
return binder
}

Expand Down

0 comments on commit 3ffec9e

Please sign in to comment.