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
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
Tutorial
How Much Does It Cost to Build a SaaS Page Builder in 2026?
How much does it cost to build a SaaS page builder in 2026? Explore realistic development costs, timelines, features, and how using GrapesJS can reduce
Tutorial
UnStudio for GrapesJS: 4 Plugins to Build Better Visual Editors
Meet UnStudio, a new GrapesJS plugin studio with four tools, safer and better editor: Command Palette, Responsive Pack, Autosave & Restore, and Autofill
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.