badgateway/react-ketting

api call is not getting trigger if following links from the state

sazyadav opened this issue · 0 comments

Hi @evert

we are trying to follow some of the links out of state and very first time when the page loads those links are not trigrring api call.

const refreshStore = (franchiseId: string, storeId: string) => {
franchiseGroupClient.get(franchiseId).then(response => setFranchiseGroup(response));
storeClient.get(franchiseId, storeId, true).then(({ data, state }) => {
if (state.links.has('region')) regionClient.fromResource(state.follow('region')).then(setRegion);
if (state.links.has('area')) areaClient.fromResource(state.follow('area')).then(setArea);
if (state.links.has('close')) setStoreCloseURL(state.links.get('close')!.href);
if (state.links.has('open')) setStoreOpenURL(state.links.get('open')!.href);
if (state.links.has('reopen')) setStoreReopenURL(state.links.get('reopen')!.href);
if (state.links.has('finalize')) setStoreFinalizeURL(state.links.get('finalize')!.href);
if (state.links.has('abandon')) setAbandonStoreURL(state.links.get('abandon')!.href);
setStore(data);
});
storeClient.assignments(storeId).then(setTeamRoster);
};

this is our fromREsource
fromResource = async (resource: Resource): Promise => resource.get().then(this.fromState);
abstract fromState(state: State): Promise;

so in regionClient.fromResource(state.follow('region')).then(setRegion); we are trying to follow the region link but at the pagload time it is not calling the api but when we refresh the page, api call is getting triggered..

COuld you please help me to call the api first time (at the page load only).. why after refresh it calls the api?