ukrbublik / react-awesome-query-builder

User-friendly query builder for React
https://ukrbublik.github.io/react-awesome-query-builder
MIT License
1.91k stars 490 forks source link

v6.5.x of core package requires to define an empty action on init the state of the tree. #1056

Closed gquittet closed 4 weeks ago

gquittet commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

With the v.6.4.x and below we can directly load the tree like this:

const config = CoreConfig;
const reducer = TreeStore(config)
const state = reducer({ tree: initTree })

CoreConfig is imported from "@react-awesome-query-builder/core"

initTree is just an empty tree build like this:

Utils.loadTree({
  id: Utils.uuid(),
  type: "group",
  children1: []
})

Now starting with v6.5.x, we have to define an empty action just to access the config because getLastConfig is undefined.

const config = CoreConfig;
const reducer = TreeStore(config)
// The type INIT_TREE can be whatever you want
const emptyAction = { type: "INIT_TREE", config }
const state = reducer({ tree: initTree }, emptyAction)

Without this modification, I get this error:

ERROR TypeError: action is undefined
    tree_default tree.js:886

image

And the I can't init the state of my tree.

To Reproduce

Install the v6.5.x and try the example above.

Expected behavior

It should load the state without this empty action.

If it is expected, we have to update the documentation.

ukrbublik commented 1 month ago

Thanks for the report. It's a bug, will fix in next version