Meteor-files: link() with meteor useTracker()

Created on 26 Mar 2020  Â·  3Comments  Â·  Source: veliovgroup/Meteor-Files

I'm having an issue when using link() on a findOne() or even find() while inside useTracker()

  • here is my code that produces an error:
    const unitImageURL = useTracker(() => {
    let image = Images.findOne({
    _id: unit.images[0]
    }).link()
  • Version of Meteor you're experiencing this issue 1.10.1
  • Where this issue appears? OS (Linux)? Browser chrome
  • Is it Client or Server issue? I do not really know
  • Client logs :
    Uncaught TypeError: Cannot read property 'link' of undefined
    at Object.reactiveFn (UnitListItem.jsx:21)
    at useTracker.js:49
    at tracked (useTracker.js:79)
    at useTracker.js:129
    at Computation._compute (tracker.js:308)
    at new Computation (tracker.js:206)
    at Object.Tracker.autorun (tracker.js:576)
    at useTracker.js:128
    at Object.Tracker.nonreactive (tracker.js:603)
    at useTracker.js:127
question

All 3 comments

Hello @msgfxeg ,

For .findOne() method this is expected behaviour, you got to check if .findOne() has results. Feel free to open new (or more preferably PR) ticket to update FileCursor documentation and .find() method documentation. .findOne() method is meant to work similarly to default Mongo's .findOne() method, as it meant to return null when record is not found.

For .find() there is no .link() method as it returns FilesCursor.

Hello @dr-dimitru,
Thanks for your reply it helped me a lot.
As I am using react with meteor. the problem was that react component updates twice, the first time before the mongo query succeeded! so I have to write it as follows:

useTracker(() => {
if (
Images.findOne({
_id: unit.images[0]
}) !== undefined
) {
return Images.findOne({
_id: unit.images[0]
}).link();
}
});
P.S: a bit of redundant code but it does not heart :)

@msgfxeg I'm glad this was fixed quickly

Please support this project with:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sylido picture sylido  Â·  3Comments

Avijobo picture Avijobo  Â·  3Comments

dr-dimitru picture dr-dimitru  Â·  3Comments

owenhoskins picture owenhoskins  Â·  3Comments

RE-N-Y picture RE-N-Y  Â·  3Comments