meteorrn / meteor-react-native

Meteor client for React Native matching Meteor Spec
https://guide.meteor.com/react-native.html
Other
59 stars 31 forks source link

use withTracker with reack hooks #14

Closed Navyroot closed 4 years ago

Navyroot commented 4 years ago

could you explain me how to use withTracker with reack hooks ?

TheRealNate commented 4 years ago

Hi @Navyroot. withTracker passes your reactive data as properties to your components. Meteor recently added a hook called useTracker, but we haven't finished adding this to meteor-react-native yet. However, you can still use withTracker even with function components:

import Meteor, {withTracker} from 'meteor-react-native';

const MyComponentInner = props => {
    let {currentUser} = props;
    // ...
}

const MyComponent = withTracker(() => {
    return {
        currentUser:Meteor.user()
    };
})(MyComponentInner);
Navyroot commented 4 years ago

@TheRealNate thank you

thearabbit commented 4 years ago

+1

TheRealNate commented 4 years ago

Hi @thearabbit, this question has been resolved since withTracker resolved the author's issue. Are you interested in useTracker? In that case, you can check out PR #17.

thearabbit commented 4 years ago

Sorry, thanks for your reply. I would like to use useTracker, because want to use dynamic subscript with dynamic params?

TheRealNate commented 4 years ago

@thearabbit, have a look at PR #17 and let me know if it suits your needs. If there is something missing feel free to open a new issue. If you use PR #17 and it works well, please add a comment there letting us know so we can move closer to merging it.

thearabbit commented 4 years ago

Have any example to use? I will try to test

TheRealNate commented 4 years ago

@thearabbit I believe based on the PR you can use it like this:

import Meteor, {useTracker} from '@meteorrn/core';

const MyComponent = () => {
  let myData = useTracker(() => {
    let user = Meteor.user();
    return {user};
  });

  return <View>...</View>
}

Note that to install the repository from the PR, you should be able to use this command:

npm install --save https://github.com/sandeepjain/meteor-react-native.git

I would not recommend using the PR for production, as it won't receive updates, but if you could test it out per your use-case and let me know if it works well I can finish the review and merge the PR.

thearabbit commented 4 years ago

Thanks I will try soon.

TheRealNate commented 4 years ago

Hi @thearabbit, any updates?