Unknown cause of janky behavior in React Component
I'm building the following component which uses the standard pattern of binding convex data to a UI component directly. However, as you can see in the video, when I update data in the Convex dashboard there's some strange behavior where the state initially updates as desired, but then the component completely rebuilds, which is undesired. Am I doing something wrong?
4 Replies
Probably not related to Convex, something is causing the component to unmount. Try to simplify the problem by removing code to see what's causing what. Maybe you have another useQuery in a parent component that also reacts to the change in data.
Okay I was able to resolve the issue by updating the query of the parent to not fetch the entire document (the one I was updating in the video) and instead subscribe to the specific field that was needed on the parent. However, this feels like it increases the number of subscriptions and the problem would persist if the parent needs the same data as the child. In the latter case, would you query for the shared data in the parent and pass it down to the child?
or if both a parent and child need access to a "tableView" document would you have the parent do a getTableViewById query, pass the id to the child and have the child run the same query?
I think the issue is not in the queries, but in the fact that rerendering the parent messes up your UI. Maybe this is because of
key
on the child component?hmm I didn't have to change the key of SortItem to get it to work, but I updated the interface of the component to be
And narrowed down the scope of the tableViewQuery in the parent component
Okay it seems like passing around Ids + using React.memo to wrap components works well