Re-render trait on selected component
Thanks for reporting this, @ahmedderkaoui. Great question about Re-render trait on selected component. 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 b...
Read full answer below โQuestion
I know there is a function that can rerender the view of a trait. However, I still don't know how and where to use it.
this.editor.on('component:selected', model => {
const component = this.editor.getSelected();
const models = component.get('traits').models;
// Parsing types
for(var index in models) {
if (models[index].attributes.type == 'typeinput') {
// How to use the view.rerender() function
console.log(models[index].target.view)
}
}
});
Answers (1)
Thanks for reporting this, @ahmedderkaoui. Great question about Re-render trait on selected component. 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 operatio...
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3185
How to get the models trait of a component?
Hi there, I added a new type "array" to the TraitManager. So I can add several sub traits. On one point I have to check the traits of the m...
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...
Issue #3363
Set content function empties the component content
I am trying to use the set function to change the content of a component, but actually the result is an empty component with nothing inside...
Issue #3266
How to know from which block is the selected component generated ?
Wondering how to do a reverse lookup, from component back to block. I use Block Manager add() to add a block like below after initializatio...
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
Introducing Search on GJS.Market
GJS.Market now has one search across everything we publish โ plugins, articles, community questions, guides, authors and services. Press โK from any page.
Tutorial
GJS.Market Is Now Available for India ๐ฎ๐ณ
GJS.Market is expanding its global presence with a dedicated experience for developers, agencies, SaaS companies, and digital creators in India
Tutorial
How to Build an AI-Powered Page Builder with GrapesJS in 2026
What we learned building GJSDocs โ from simple AI text generation to structured, context-aware visual editing
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.