selectPreviousBreakpoint$(): Observable<Breakpoint | undefined>¶
The selectPreviousBreakpoint$
method allows you to get an observable with a previously active breakpoint if it existed.
Returned value¶
A returned value has a type of Observable<Breakpoint | undefined>
where Breakpoint
represents the Breakpoint model.
Example¶
In this example we make a ResolutionDetectorApi
call to get an observable with a previously active breakpoint if it exists.
useStorefront(async (storefront) => {
const resolutionDetectorApi = storefront.getApiSync('ResolutionDetectorApi');
const previousBreakpoint$ = resolutionDetectorApi.selectPreviousBreakpoint$();
previousBreakpoint$.subscribe((breakpoint) => {
if (!breakpoint) return;
console.log(`Previous breakpoint was ${breakpoint.name} which applied to screens of ${breakpoint.value}px width and below.`);
})
});