Skip to content

Commit

Permalink
Add isFetchedAfterMount
Browse files Browse the repository at this point in the history
  • Loading branch information
k-ode committed Oct 2, 2024
1 parent 6468a88 commit 4b94e90
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/mst-query/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/mst-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mst-query",
"version": "3.4.0-canary.11",
"version": "3.4.0-canary.15",
"description": "Query library for mobx-state-tree",
"source": "src/index.ts",
"main": "dist/mst-query.js",
Expand Down
8 changes: 8 additions & 0 deletions packages/mst-query/src/MstQueryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ export class QueryObserver {
options: any;
isQuery: boolean;
isMounted = false;
isFetchedAfterMount = false;

constructor(query: any, isQuery: boolean) {
this.query = query;
this.isQuery = isQuery;

makeObservable(this, {
isFetchedAfterMount: observable,
});
}

subscribe() {
Expand Down Expand Up @@ -375,6 +380,9 @@ export class MstQueryHandler {
if (!this.isFetched) {
this.isFetched = true;
}
this.queryObservers.forEach((observer) => {
observer.isFetchedAfterMount = true;
});

if (this.model.isMutation) {
this.notify({ onMutate: true }, data, this.model);
Expand Down
3 changes: 2 additions & 1 deletion packages/mst-query/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getSnapshot, getType, Instance, isStateTreeNode, SnapshotIn } from 'mobx-state-tree';
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
import { useContext, useEffect, useRef, useState } from 'react';
import { VolatileQuery, MutationReturnType, QueryReturnType } from './create';
import { Context } from './QueryClientProvider';
import { QueryClient } from './QueryClient';
Expand Down Expand Up @@ -81,6 +81,7 @@ export function useQuery<T extends Instance<QueryReturnType>>(
query: query,
refetch: query.refetch,
isStale: query.__MstQueryHandler.isStale(options),
isFetchedAfterMount: observer.isFetchedAfterMount,
};
}

Expand Down

0 comments on commit 4b94e90

Please sign in to comment.