File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
packages/react-meteor-data Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,19 @@ if (Meteor.isServer) {
11
11
}
12
12
else {
13
13
useTracker = ( reactiveFn , dependencies ) => {
14
- const [ trackerData , setTrackerData ] = useState ( null ) ;
15
14
const callback = useCallback ( reactiveFn , dependencies ) ;
16
15
16
+ // Run the function once with no autorun to get the initial return value.
17
+ // @todo Reach out to the React team to see if there's a better way ? Maybe abort the initial render instead ?
18
+ const [ trackerData , setTrackerData ] = useState ( ( ) => {
19
+ // We need to prevent subscriptions from running in that initial run.
20
+ const realSubscribe = Meteor . subscribe ;
21
+ Meteor . subscribe = ( ) => ( { stop : ( ) => { } , ready : ( ) => false } ) ;
22
+ const initialData = Tracker . nonreactive ( callback ) ;
23
+ Meteor . subscribe = realSubscribe ;
24
+ return initialData ;
25
+ } ) ;
26
+
17
27
useEffect ( ( ) => {
18
28
let computation ;
19
29
// Use Tracker.nonreactive in case we are inside a Tracker Computation.
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export default function withTracker(options) {
21
21
} ) ;
22
22
}
23
23
24
- return data ? < Component { ...{ ...props , ...data } } /> : null ;
24
+ return < Component { ...{ ...props , ...data } } /> ;
25
25
}
26
26
27
27
return pure ? memo ( WithTracker ) : WithTracker ;
You can’t perform that action at this time.
0 commit comments