How to track the updates of components down the tree?
I'd create a specific listener on the parent then I'd trigger that event from the child
Read full answer below ↓Question
Hi, @artf. I have a few questions regarding component lifecycle hooks.
-
In my application, I want to track the updates to all the children of a component and their children, and so on. How should I do it?
-
Updates on immediate children are tracked by the
model.updated()hook but I need to track the updates to a component (let's call this a super child) which is a nested child of some other component (let's call this super parent). In between the super parent and the super child, there can be any number of components. How can I track these updates? e.g. If I add a component to the super child, I want to do some stuff in the super parent.
Also, I can't track the changes on a global level. I want to do it at the component level.
<hr/> To add more context to my problem, this is what I am trying to do:<br/> I have a custom component inside which the user can have a grid-like structure based on the number of columns specified in the traits. A grid has multiple custom cell components that are similar. <br/> Each grid cell is editable and if the user changes one grid cell (adds or removes components), other grid cells get the update.<br/> To keep a track of the changes I am making use of an attribute on the custom grid component. The attribute is like a blueprint of the cells in the grid (it represents the cell structure and its the cell component which is updated latest)Answers (2)
I'd create a specific listener on the parent
// parent component
...
init() {
this.on('cell-changed', this.doStuff)
}
then I'd trigger that event from the child
updated() {
const parent = this.closestType('grid-type');
parent && parent.trigger('cell-changed', { keys: 'values' })
}
Thanks for reporting this, @theSC0RP.
Great question about How to track the updates of components down the tree?. The recommended approach with Components is to use the event-driven API.
Start here:
- Check the GrapesJS documentation for your specific module
- Look for the
on()event listener method - Most operations can be achieved by listening to editor and component events
Common patterns:
// Listen for changes
editor.on('change', () => console.log('something changed'));
// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));
If you're still stuck:
- Share a minimal CodeSandbox reproduction
- Include what you've already tried
- Mention your GrapesJS version
- The community is here to help!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3328
How can I update the nodeValue (text value) of components by inputs forms
Hello. Grapesjs is a great tool. Thanks for it. I want to update the text value of a component by inputs, how can I do that?? if a user fil...
Issue #3213
How to save the dynamically added traits
Hi, @artf, I have a custom component that has a button trait. When the button is pressed, I am adding a custom trait dynamically using comp...
Issue #4735
resetId types mismatch
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? n/a Reproducible demo link n/a Describe th...
Issue #3586
how to listen the components change in a component.
init() { this.listenTo(this.model,'change:components', this.handleComponentsChange); }, I develop a component, I try to listen the child co...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
GrapesJS vs Webflow vs Tilda: What to Choose for Your Business in 2026
Choosing the right website platform in 2026 is no longer just about building a site
Tutorial
GJS Market 2.0 - Donations, Tracking, Labels and Better Product Discovery
We’ve rolled out a new set of GrapesJS marketplace updates across GJS Market, focused on improving how creators distribute products
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.