Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tbassetto opened this issue Jun 19, 2024 · 2 comments

Comments

@tbassetto
Copy link

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
Copy link
Member

stipsan commented Jun 20, 2024

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
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants