-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[email protected]: can't use hooks in withTracker #363
Comments
This seems to be a regression introduced in 384da2f . In the app where I have a bunch of hooks inside withTracker the whole app goes to infinite loop of rendering (both react v17 and v18). Maybe it is related to the "an attempt to retain the "side-effect" |
It's not really a regression, because you really shouldn't be using other hooks within Meteor really should not support this in Instead, you should compose your hooks within another hook (or hoc), so that they work side by side, and not nested. |
You can make your own hoc out of const withMahStuff = (Component) => (props) => {
const links = useTracker(() => {
return LinksCollection.find().fetch()
}, [])
const contextValue = useContext(TestContext)
const newProps = {
...props,
links,
contextValue
}
return <Component {...newProps} />
}
export default withMahStuff(Info) Check out more examples from the old useTracker post on medium. |
Let's deprecate |
I agree with you, @StorytellerCZ - or at least- give some guidance on the warning. |
It seems that in 2.5.1 you can't use hooks inside withTracker anymore. I referenced this issue in #354 (comment) and now I am creating a separate issue for it.
Please take a look in the reproduction repository:
https://github.com/wolasss/meteor-react-data-2.5.1-bug
I used meteor react boilerplate, I simply added
useContext
inwithTracker
to demonstrate the issue:Well, it does not have to be
useContext
but any other hook. It throws an error:If you switch to v2.4.0, the problem does not exist (branch
v2.4.0
in reproduction repo)The text was updated successfully, but these errors were encountered: