Skip to content

Is there any way to perform transient updates (equivalent to Zustand useStore.subscribe)? #610

Closed Answered by dai-shi
looeee asked this question in Q&A
Discussion options

You must be logged in to vote

Short answer is no.

It's like useState, so updating ref requires useEffect like you do.
One thing you might try is to update the ref in a child component.

function DodecahedronJotai({ ...props }) {
  console.log("render Jotai")

  const material = useRef()

  return (
    <>
      <mesh {...props}>
        <dodecahedronBufferGeometry attach="geometry" />
        <meshStandardMaterial ref={material} attach="material" transparent={true} roughness={0.75} emissive="#404057" />
      </mesh>
      <SyncTransparent material={material} />
    </>
  )
}

function SyncTransparent({ material }) {
  const [transparentJotai] = useAtom(transparentAtom)

  useEffect(() => {
    material.current.opacity = 

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
5 replies
@looeee
Comment options

@dai-shi
Comment options

@looeee
Comment options

@dai-shi
Comment options

@looeee
Comment options

Answer selected by looeee
Comment options

You must be logged in to vote
5 replies
@dai-shi
Comment options

@timedtext
Comment options

@tpatalas
Comment options

@dai-shi
Comment options

@tpatalas
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants