Computed property

A computed prop is a derived value automatically calculated from other data (props, state) that updates whenever its dependencies change.

Examples

Logo of react React 19, Functional components
Logo of vue Vue 3.5, Composition API

No caching

The simplest derived values can be computed every re-render without any extra complexity but with probable over-computing.

Logo of react React 19, Functional components

The regular const variable can be as a computed value with updating the value each re-render.

Use regular functions if the computed value doesn't know the original source of the value in advance:

Logo of vue Vue 3.5, Composition API

To update a value every re-render use a function (instead of computed). Functions are not cached.

Use regular functions if the computed value doesn't know the original source of the value in advance:

Caching

Logo of react React 19, Functional components

Wrap with useMemo to cache computed value to avoid recompute the value if the source variables are not changed. React docs

Logo of vue Vue 3.5, Composition API

Vue caches computed by default. Vue docs

Writeable

Logo of react React 19, Functional components
Logo of vue Vue 3.5, Composition API