Skip to content
Source
Sign inSign up
TanStack/table

Unable to subscribe to table.options.meta #6236

Send to my agent
Closedkevinpastor(GitHub profile, opens in a new tab) opened this issue 3 comments

TanStack Table version

v9.0.0-alpha.32

Framework/Library version

React v19.2.5

Describe the bug and the steps to reproduce it

The table.Subscribe component does not provide a way to subscribe to meta changes. This causes children to become stale.

In the reproducible example, a state is directly attached to the meta of the table. Even though the selector provided to table.Subscribe is the most flexible possible, the value of table.options.meta does not change in the child component.

https://codesandbox.io/p/devbox/tanstack-react-table-invalid-type-forked-4k7vqy?workspaceId=ws_Pp3ZEt42nesyEqh1UGzCFD

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

No, because I do not have time to dig into it

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
  1. KevinVandycommented

    Before I even saw this issue, the new alpha I shipped today apparently made this possible like this:

          <table.Subscribe
            atom={table.optionsStore}
            selector={(options) => options.meta}
          >
            <></>
          </table.Subscribe>

    Although, I'm probably going to now rename atom to source since it works for both atoms and stores.

    So this should work soon:

          <table.Subscribe
            source={table.optionsStore}
            selector={(options) => options.meta}
          >
            {(meta) => <>{JSON.stringify(meta)}</>}
          </table.Subscribe>

    You can also just use a useSelector (formerly useStore) hook imported from @tanstack/react-store for any tanstack store/atom to make it reactive where you need it.

  2. Thanks Kevin for the quick answer 😉 I'll try this out today. This seems promising!

  3. Using useSelector(table.optionsStore, (options) => options.meta) seems to work as expected.

    I was going to say that it is unfortunate that a parent rerender is not propagate through table.Subscribe, which would be the expected behaviour with React, but I realized that there is probably some React.memo involved in that HOC.

Sign in to join this conversation.