@action — auto pending / error / result
React 19 useActionState parity: any method decorated with @action exposes { pending, error, result } in the template under the action's own name.
@action
dj-form-pending
@server_function
dj-transition
ActivityMixin
WizardMixin
dj_suspense
defer()
DataTableMixin
dj-virtual
dj-viewport
UploadMixin
Save a note
@actionLast saved: nothing yet
The whole pattern
Compare to useState(loading) + setLoading(true) + try/catch + setError() + setData() in a React component. Here it's one decorator.
from djust import action
class NoteView(LiveView):
@action
def save_note(self, text: str = '', **kwargs):
# Templates auto-read save_note.{pending, error, result}
time.sleep(0.4) # simulate API latency
if not text:
raise ValueError('Empty') # becomes save_note.error
self.note = text
return {'saved_at': now()} # becomes save_note.result
See docs.djust.org/guides/server-actions/ for the full guide.