- Home
- Javascript
- useEffect & Derived Values
useEffect & Derived Values
Contents
useEffect & Derived Values
A. useEffect lets a component run code in response to something changing, outside of the normal render flow.
In JobForm, useEffect watches the job prop being passed in — when the admin clicks Edit on an existing job, the effect fires and pre-fills the form fields with that job's current data; when Add Job is clicked instead, it resets the form back to empty. This allows a single modal component to handle both "adding" and "editing" without duplicating any code.
B. Derived/computed values are new pieces of information calculated from existing data, instead of being stored as their own separate state.
On the Employer Dashboard, the numbers shown on the StatCard components for Total Jobs and Total Applicants aren't stored anywhere by themselves — they're calculated live as jobs.length and applications.length every time the component renders, so they're always accurate without any extra state to keep in sync.









