Development questions
What is reactivity in LWC and when does a field trigger a re-render?
DevelopmentEasy
A component re-renders when a reactive field used in the template changes.
- Since Spring '20, all class fields are reactive, but only on reassignment (primitives, or assigning a new object/array).
- To react to mutations inside an object or array (e.g.
this.obj.name = 'x'orthis.list.push(x)), either use@trackor reassign a new copy:this.list = [...this.list, x];. @apiproperties are reactive but owned by the parent, so don't mutate them in the child.- Getters are re-evaluated on each render.
Only fields actually used in the template (or getters used there) trigger a re-render.
lwcreactivityfundamentals
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?