State undefined on wp-init when using custom blocks in router region #60306
poof86
started this conversation in
Interactivity API
Replies: 1 comment
-
Hey @poof86, can you give us a repository with the block and steps to reproduce the issue? It's hard to know what's working on without looking at the code. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using the core Query block to load my own interactivity enabled blocks. These blocks use the wp-init directive that call a callback that is defined with store() in the view script for that block.
It seems that the store in the view script hasn't initialised yet when this block is loaded for the first time during a query region update. when the wp-init directive is "called" it's giving the error Uncaught TypeError: Cannot read properties of undefined at hooks.tsx:272:50
I'm not sure if this is een Issue or that I'm doing something wrong.
For now the callback function is moved to a block view.js that I know will be persistent on the page, this way I can be sure the callback will be defined.
I also notice that the return function of the wp-init callback (which is called when the element is unmounted) the wp-context is lost. The context is needed so that the selected/checked element that is unmounted can removed van a list of selected items. I was able to get the context back by returning a withScope function, but I am assuming this shouldn't be needed?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions