mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 350 forks source link

When using useEffect(), an error appears: Warning: React has detected a change in the order of Hooks called by wrappedComponent. This will lead to bugs and errors if not fixed. #827

Closed it-efrem closed 4 years ago

it-efrem commented 4 years ago

Repository -> https://github.com/Evgeny-Bukovski/MobX-React-ToDo-Example-forms-fetch-async Commit with errors-> https://github.com/Evgeny-Bukovski/MobX-React-ToDo-Example-forms-fetch-async/commit/70260f861cdceb100e35eb3308f7f6ddb12f5e59

I expect a list item to be added without errors.

mweststrate commented 4 years ago

You are calling a component as a function. Instead of store.map(Item) do store.map(item => <Item .... />) (note that this is further unrelated to MobX)

it-efrem commented 4 years ago

Isn't using a store.map(item => <Item .... />) a bad approach?

mweststrate commented 4 years ago

No, why would it be? That is the only normal way of doing that in React I know :). It maps from values to component invocations. What you where doing was mapping from value to render logic, which would effectively create one gigantic React component that does everything. See for example https://kentcdodds.com/blog/dont-call-a-react-function-component

it-efrem commented 4 years ago

store.map(item => <Item {...item}/>) It works! Thanks for the quick reply and for the link to the article 💪

it-efrem commented 4 years ago

@mweststrate

I am guided by this, because an arrow function is also created here store.map(item => <Item {...item}/>)

Docs: https://reactjs.org/docs/faq-functions.html image

mweststrate commented 4 years ago

That is about passing arrow functions to other components, not the use of arrow functions inside the implementation (which useEffect etc do as well)

On Wed, Feb 5, 2020 at 12:54 PM Eugene Bukowski notifications@github.com wrote:

@mweststrate https://github.com/mweststrate

I am guided by this, because an arrow function is also created here store.map(item => <Item {...item}/>)

Docs: https://reactjs.org/docs/faq-functions.html [image: image] https://user-images.githubusercontent.com/20017668/73843418-abba5680-482f-11ea-8337-56f1432e4720.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx/issues/2272?email_source=notifications&email_token=AAN4NBHADCESJRKLVDQNIXDRBKZJBA5CNFSM4KQKHTVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK3KBFA#issuecomment-582394004, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBBTU7IUE56DUPJ5PL3RBKZJBANCNFSM4KQKHTVA .

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.