Skip to content

Is the syntax between state slice selection and transient update equivalent? #194

Closed Answered by jwrubel
jwrubel asked this question in General
Discussion options

You must be logged in to vote

I think I figured out the issue here. My Store looks generally like:

const useStore = create((set, get) => ({
  foos: [],
  createFoos: () => {
    ...
    set(state => ({ foos: createdFoos }));
},
...

In a component I call createFoos() and I can verify they're created and now part of the state.

In a component that's part of a react-three-fiber canvas I have:

const Foos = () => {
  const foosRef = useRef(useStore.getState().foos);
  useEffect(() => {
    useStore.subscribe(
      foos => (foosRef.current = foos), 
      state => state.foos
    )
  }, [])
  
  const renderFoo = (foo) => {
    return <Foo key={foo.id} data={foo} />
  }
  
  return (
    foosRef.current.map(foo => renderFoo…

Replies: 1 comment 3 replies

Comment options

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

@jwrubel
Comment options

@dai-shi
Comment options

Answer selected by jwrubel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants