react-native-meteor-hooks ☄️
React Native Hooks for Meteor. It was never easier to integrate React into the Meteor stack.
Usage
Just import the hooks you need from this module and you are ready to use Meteors reactive data in React Native. All Meteor computations from the hooks are stopped automatically when the component is removed from the tree.
const UserWidget = { const currentUser = return <View> currentUser ? <Text> currentUseruserName </Text> : <Text>You are not logged in</Text> </View> }
Available Hooks
useTracker( Function: trackerFun [, Array: deps] ) : trackerFunResult
Runs a function inside Trackr.autorun
and can return reactive data.
const UserBooks = { const data = // pass [sortBy] as second arg - so that this function will be rerun if sortBy changes const books = datauserBooks // ...}
useSubscription( String: subscriptionName [, ...subscriptionParams] ) : Boolean
Subscribes to a publication and returns a reactive "loading" var.
const UserBooks = { const loading = // subscription will be rerun if showLimit changes if loading // ... // ...}
useMongoFetch( MongoQuery: query [, Array: deps] ) : Array | Object
Fetches a MongoQuery and returns the result.
const UserBooks = { const loading = if loading // ... else const allBooks = const books = allBooks // ... }
useCurrentUser() : Object | null
Returns the current logged in User or null.
const UserBooks = { const user = if user const loading = if loading // ... else // ... }
Note
This package was inspired by a blog post of ARTHUR ANDERSEN. Go check out his blog!