Get the query that is currently rendering #922
-
|
Sorry if this is obvious but how do I get the query state of the currently rendering query in say a custom control component. See https://codesandbox.io/p/sandbox/jsv6mw for an example. In the example above I change the root combinator to "OR" then hit "Reset to default" button at the top. When the I hope that I'm making sense here 😅 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
|
I'm on mobile so haven't looked at the sandbox, but I think what you're looking for is the Docs here: https://react-querybuilder.js.org/docs/utils/hooks If you need to access the current query from an event handler, use |
Beta Was this translation helpful? Give feedback.
Ok I see what you mean. That hook (among other things) works because RQB uses Redux internally to manage state. This works well when
QueryBuilderis used as an uncontrolled component. If you use it as a controlled component—by updating thequeryprop—it will see that the newqueryprop is different from what's in the Redux store during the render due to the prop change and then dispatch an action to sync the Redux store with the prop, causing another render.But really, two renders with the same props shouldn't cause any performance issues unless you have some separate, underlying issue.