sanity-io / react-rx

React + RxJS = <3
https://react-rx.dev
MIT License
43 stars 7 forks source link

You recommend useMemoObservable in your documentation, what's the replacement in v3? #96

Open tbassetto opened 4 months ago

tbassetto commented 4 months ago

Not really a bug bu I have code in my studio based on https://www.sanity.io/docs/studio-react-hooks#7a5503c777f4:

import {useMemoObservable} from 'react-rx'

export function MyComponent() {
  const docId = useFormValue(['_id'])
  const documentStore = useDocumentStore();
  const results = useMemoObservable(() => {
    return documentStore.listenQuery(
      `*[_type == 'article' && references($currentDoc) && !(_id in path("drafts.**"))]`,
      {currentDoc: docId},
      {}
    )
  }, [documentStore, docId])

    return (
      /** Render component */
    )
}

Latest sanity comes with react-rx 3.0.0 which removes useMemoObersable but does not advice , any recommendation? The documentation should be updated too. Thanks!

stipsan commented 4 months ago

Hi @tbassetto! 👋

I wasn't aware we had docs dependencies to this change, or that react-rx is used outside of our own internals. Thanks for flagging! I'll let the docs team know, and see if we can add a migration section to the README to help others 😄

Here's your snippet on v3:

import {useMemo} from 'react'
import {useObservable} from 'react-rx'

const INITIAL_STATE = []

export function MyComponent() {
  const docId = useFormValue(['_id'])
  const documentStore = useDocumentStore();
  const observable = useMemo(() => 
    documentStore.listenQuery(
      `*[_type == 'article' && references($currentDoc) && !(_id in path("drafts.**"))]`,
      {currentDoc: docId},
      {}
    )
  , [documentStore, docId]);
  const results = useObservable(observable, INITIAL_STATE);  

    return (
      /** Render component */
    )
}
tbassetto commented 4 months ago

Thanks!