-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Unable to use {forwardRef: true} option of observer HOC #2524
Comments
Thanks for the report. That option works only with |
Sorry, I'm still trying to grasp the relationship between mobx-react and mobx-react-lite. I appreciate the latter is with hooks. Am I correct in saying that mobx-react-lite is its own library with a degree of independence from mobx-react and can be used in a hooks only implementation, but since mobx-react includes mobx-react-lite in its packaging, the mobx-react-lite API becomes part of the mobx-react API, but with exceptions (like this example) that may be in mobx-react-lite and not mobx-react but are documented in mobx-react for consistency? |
That is correct. Perhaps this overview will help you? https://mobx-react.js.org/libraries The Actually, looking at the code, it seems that you should be able to wrap to |
Yea, here is a quick demo. https://codesandbox.io/s/xenodochial-wiles-3zvwk?file=/src/App.js Such inconsistency is of course bad for any future migrations. I am thinking we should probably make it work the same way in |
@FredyC thank you, It help me a lot. the demo is useful.
and
both work. |
I think you are missing the point here. It should work the same way across both libraries. |
@FredyC I mean the below code should not work because of the code. The comment of source code is for this case. So this case maybe not a bug.
|
I am very interested in fixing this problem. Is there anything I need to pay attention to?(eg: which version should I fix it?) |
@yuwanlin I am thinking it should work the other way around and expand |
Even though this issue holds more information, the #2527 is more up to date. Closing this as duplicate. |
Hello! This helps me: reduxjs/react-redux#914 (comment) |
Intended outcome
I would like to forward a ref to an observed component as per my current understanding of https://mobx-react.js.org/observer-hoc
Actual outcome
As per codesandbox below, React chokes:
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Warning: Unexpected ref object provided for div. Use either a ref-setter function or React.createRef().
The above error occurred in the
in div (at App.js:29)
in _c4 (at App.js:18)
in div (at App.js:16)
in App (at src/index.js:9)
in StrictMode (at src/index.js:8)
How to reproduce the issue
https://codesandbox.io/s/inspiring-colden-uettu?file=/src/App.js
Versions
react: 16.12.0
mobx: 5.15.4
mobx-react: 6.2.2
The text was updated successfully, but these errors were encountered: