admin管理员组文章数量:1296401
I'm working on a plugin with Gutenberg integration. I registered a plugin in React, and my sidebar is showing and working fine. But I need to perform an action each time my sidebar is showing up.
I noticed that functions Render, componentDidUpdate, componentDidMount are not called when I switch the sidebar (for example I open Rank Math sidebar, and then I return to my sidebar). So using those are not good for me.
I'm looking for some kind of event listener that will be executed when I reopen my sidebar. I'm new to React, so I'm not sure if I can use useState hook in some way to do this?
Furthermore, I also field at looking for any built-in events in Gutenberg in documentation, so not sure if there is any ready solution.
I'm working on a plugin with Gutenberg integration. I registered a plugin in React, and my sidebar is showing and working fine. But I need to perform an action each time my sidebar is showing up.
I noticed that functions Render, componentDidUpdate, componentDidMount are not called when I switch the sidebar (for example I open Rank Math sidebar, and then I return to my sidebar). So using those are not good for me.
I'm looking for some kind of event listener that will be executed when I reopen my sidebar. I'm new to React, so I'm not sure if I can use useState hook in some way to do this?
Furthermore, I also field at looking for any built-in events in Gutenberg in documentation, so not sure if there is any ready solution.
Share Improve this question asked Jul 14, 2022 at 13:08 mWinmWin 1365 bronze badges 2- 1 There isn’t an event. That’s not really how React or the block editor works. What sort of thing do you need to happen when switching tabs. Knowing that would help inform the appropriate solution. – Jacob Peattie Commented Jul 14, 2022 at 16:10
- @JacobPeattie I need to put dynamic content using iframe into the sidebar. Currently, I can load it properly, but when I change the sidebar and then return to my sidebar, the dynamically loaded content is gone. So my idea was to catch the event when sidebar is loaded and insert content then. – mWin Commented Jul 15, 2022 at 7:18
1 Answer
Reset to default 1For everyone who is looking for a solution:
The issue was that I wanted to use React. Component as I was sure it is required by WordPress. But Functional Component is also accepted, and in this case instead of componentDidMount you can use useEffect hook, which is executed each time sidebar is loaded and do the job perfectly.
本文标签: plugin developmentCatching Gutenberg sidebar switch event
版权声明:本文标题:plugin development - Catching Gutenberg sidebar switch event 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738499101a2090162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论