
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-meteor-hooks
Advanced tools
React Hooks for Meteor. It was never easier to integrate React into the Meteor stack.
Just import the hooks you need from this module and you are ready to use Meteors reactive data in React. All Meteor computations from the hooks are stopped automatically when the component is removed from the DOM.
import React from 'react'
import { useCurrentUser } from 'react-meteor-hooks'
const UserWidget = () => {
const currentUser = useCurrentUser()
return(
<div>
{ currentUser ? <p>{ currentUser.userName }</p> : <p>You are not logged in.</p> }
</div>
)
}
Runs a function inside Tracker.autorun and can return reactive data.
import React from 'react'
import { useTracker } from 'react-meteor-hooks'
const UserBooks = (sortBy) => {
const data = useTracker(() => {
const userProfile = Meteor.user().profile
const userBooks = Books.find({ _owner: Meteor.userId() }, { sort: { [sortBy]: -1 }})
return { userProfile, userBooks }
}, [sortBy])
// pass [sortBy] as second arg - so that this function will be rerun if sortBy changes
const books = data.userBooks.map(Book)
// ...
}
Subscribes to a publication and returns a reactive "loading" var.
import React from 'react'
import { useSubscription } from 'react-meteor-hooks'
const UserBooks = (sortBy, showLimit) => {
const loading = useSubscription('user_books', showLimit)
// subscription will be rerun if showLimit changes
if (loading) {
// ...
}
// ...
}
Returns { isLoading, data, error, call } object to work with meteor methods.
Full example including useEffect at https://codesandbox.io/s/kj9zqqyrr
import React from 'react'
import { useMethod } from 'react-meteor-hooks'
const UserBooks = () => {
const { isLoading, data, error, call } = useMethod('add_book', { transform: result => result.updatedAt = new Date() })
if (isLoading) return 'Adding book...'
if (error) return `Error: ${err.message}`
return (
<div>
<button
onClick={async () => {
await call('Moby Dick')
console.log('Meteor call completed')
}}
>
Add
</button>
{data && (
<p>New book added at {data.updatedAt.toLocalString()}. ID: {data.id}</p>
)}
</div>
)
}
export default UserBooks
Fetches a MongoQuery and returns the result.
import React from 'react'
import { useMongoFetch, useSubscription } from 'react-meteor-hooks'
const UserBooks = (sortBy, showLimit) => {
const loading = useSubscription('user_books', showLimit)
if (loading) {
// ...
} else {
const allBooks = useMongoFetch(Books.find({}, { sort: { [sortBy] : -1 }}), [sortBy])
const books = allBooks.map(/* ... */)
// ...
}
}
Returns the current logged in User or null.
import React from 'react'
import { useCurrentUser, useSubscription } from 'react-meteor-hooks'
const UserBooks = (sortBy, showLimit) => {
const user = useCurrentUser()
if (user) {
const loading = useSubscription('user_books', showLimit)
if (loading) {
// ...
} else {
// ...
}
}
}
Returns value of a Session var.
import React from 'react'
import { useSession } from 'react-meteor-hooks'
Session.set('currentPage', 1)
const UserBooks = (sortBy, showLimit) => {
const page = useSession('currentPage')
// ...
}
This package was inspired by a blog post of ARTHUR ANDERSEN. Go check out his blog!
FAQs
React Hooks for Meteor.
The npm package react-meteor-hooks receives a total of 1,152 weekly downloads. As such, react-meteor-hooks popularity was classified as popular.
We found that react-meteor-hooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.