Hooks
Ember doesn't have React-style hooks, so each of these takes the component that owns it (usually this) and cleans up when that component is destroyed.
| Hook | What it does |
|---|---|
usePoll(this, 2000, { only: ['stats'] }) | Reloads on an interval. Returns { polling, start(), stop() }. Pass { autoStart: false } to start it yourself. |
usePrefetch(this) | { isPrefetched, isPrefetching, lastUpdatedAt, flush() } for the current page. |
useRemember({ view: 'grid' }, 'Posts/view') | A tracked object that survives back and forward. It doesn't need an owner. |
useProp(this, 'stats') | { value, loading, loaded } for a single prop. |
ts
import Component from '@glimmer/component';
import { usePoll } from 'inertia-ember';
export default class Dashboard extends Component {
poll = usePoll(this, 2000, { only: ['stats'] });
toggle = () => (this.poll.polling ? this.poll.stop() : this.poll.start());
}The demo's Live page polls its stats every two seconds, with a pause button. See its source, or
try it ↗ .Layout props
setLayoutProps({ title }) and setLayoutProps('sidebar', { open }) hand props to layouts from inside a page.
Re-exports
router, http, progress and config are re-exported from @inertiajs/core.