Skip to main content

Page Data Resolver

The pageDataResolver is designed to handle API calls required on every route change of the application. This function is executed by the theme engine, which gets the themeId, router, and the fpi instance as arguments - and performs asynchronous calls to fetch essential data. The Theme Engine manages the function call; theme developers just need to define the function.

Example

//helper/lib
export async function pageDataResolver({ fpi, router, themeId }) {
const state = fpi.store.getState();
const pageValue = getPageSlug(router);
const APIs = [ ]
const currentPageInStore = state?.theme?.page?.value ?? null;

if ( pageValue && pageValue !== currentPageInStore ) {
APIs.push(
fpi.theme.fetchPage({
pageValue,
themeId,
}).then(console.log)
)
}
return Promise.all(APIs).catch(console.log);
}
// Export it from index.jsx file
import { pageDataResolver } from "./helper/lib";
return {
pageDataResolver
//other keys....
}

Was this section helpful?