mobx: displayName not working in React 17 with observer
Intended outcome:
In this old issue (https://github.com/mobxjs/mobx/issues/141) it states the below should work. Also In the docs it states it will be fixed in React 17.
export const MyComponent2 = observer(() => "hello2!");
MyComponent2.displayName = "MyComponent2";
Is this an issue with observer now and/or should the docs be updated to say displayName does not work with observer?
Actual outcome:
Viewing βReact DevToolsβ in CodeSandbox notice _c3 for the MyComponent2 name:
How to reproduce the issue: https://codesandbox.io/s/mobx-displayname-reat-17-z61pb?file=/src/MyComponent.jsx
Versions
- mobx: 6.0.4
- mobx-react: 7.0.5
- react: 17.0.1
- react-dom: 17.0.1
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 23 (9 by maintainers)
TL;DR
React v17 support set memo displayName, but only can set displayName once!
Code analysis
You can only set displayName once.
I rebuild react to solve it π https://codesandbox.io/s/mobx-displayname-reat-17-forked-gfyx3
<div style="display:flex;justify-content:center;width=650px;">
</div>Expected Devtools Shown
<div style="display:flex;justify-content:center;width=650px;">
</div>React displayName
React version 17.0.1 π https://codesandbox.io/s/react-17-memo-displayname-forked-yk4u0
<div style="display:flex;justify-content:center;width=650px;">
</div>Can react component set displayName multiple times ?
React component and mobx-react
So you canβt change memo componentβs displayName now.
Previous Try
This solution is not useful, cause mobx-react didnβt do anything wrong. π
Final Conclusion
I will create a PR for facebook/react soon , but not sure it will be accepted.
Thanks for creating the PR in
facebook/react, hopefully, they will process it soon-ish.We are generally promoting based on as-needed basis, not based on people desires π Just continue to be active for now and when you need elevated permissions, you will get them.