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
Vanilla GrapesJS vs GrapesJS With Plugins: What You Actually Get Out of the Box (2026)
New to GrapesJS? See exactly what the stock editor gives you, where it falls short, and which plugins close the gaps β a beginner-friendly 2026 comparison
Tutorial
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component β click to select, then one-click fix.
Tutorial
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners β this post is for you.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.