Effect Window Resize

Listen to the window resize event and store the inner width.

Effect: event (window resize) + set

Window width =

Resize the browser window; value updates live.

PHP
<?php // model $winW = state(0); // UI $app = fragment([ el('div', [cls('container my-5')])], [ el('h1', [], [ text('Effect: event (window resize) + set') ]), el('p', [], [ text(concat('Window width = ', read($winW))) ]), el('p', [cls('text-muted')], [ text('Resize the browser window; value updates live.') ]), ]), // EFFECT: listen to window resize, set $winW from the event (window.innerWidth) onWindow('resize', [ set($winW, ev('target.innerWidth'), true) // asAction = true ]), ]);