Documentation · Chapter 10

Coordinate effects and asynchronous work.

Effects run when dependencies change and support debounce, throttle, cleanup, and latest-only concurrency.

Every lesson starts from the problem, explains the mechanism, then gives a concrete verification.

Attribute or function

#[Effect] names a method and keeps logic reusable. Effect() inside body resembles React's placement and is convenient for local behavior. Both forms may coexist.

phpaml — zsh
#[Effect('search', runOnMount: false, debounce: 250, concurrency: 'latest')]
private function search(): ClientInstruction
{
    return Api::get('/api/search', ['q' => $this->state('search')])
        ->thenSet('results');
}

Avoid outdated responses

Debounce waits for quiet, throttle caps frequency, and concurrency latest cancels relevance of an older result when a newer request starts.

Backend calls remain visible

Api::get/post/put/patch/delete creates an explicit network instruction. A local state change never silently becomes an HTTP request.