Skip to main content

PageDataResolver

pageDataResolver is designed to handle API calls required on every route change of the application. This function is executed by the theme engine and it gets the themeId, router and the fpi instance as arguments - and performs asynchronous calls to fetch essential data. The function calling is managed by the Theme Engine; 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?