Automatically wrap all components with observer
via a Babel plugin?
#3839
guillaumebrunerie
started this conversation in
Ideas
Replies: 1 comment
-
It's possible with a caveat that you need a convention for indentifying a component function (eg first letter is uppercased, body contains JSX, ...). Personally I don't think it's worth it. It's recommended to use a named function instead of Our eslint plugin implements an autofix feature you may find useful: Also check: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm new to MobX and so far it seems very interesting, except that it feels a bit annoying having to wrap every single component with
observer
, especially given that it breaks the name shown in the React Dev Tools when using arrow functions (I have seen the various workarounds at https://mobx.js.org/react-integration.html#displayname but neither of them seem particularly nice to me).But I was wondering, would it be possible to write a Babel plugin that automatically wraps every component defined in the code base with
observer
, and also setsdisplayName
appropriately? It feels like it shouldn’t be too difficult to do. Or would that be a bad idea?I also saw #3798 which doesn’t require a Babel plugin, but I don’t think it solves the
displayName
problem, and it also probably also deeply wraps components from external libraries, which is probably not a good idea.Example:
Beta Was this translation helpful? Give feedback.
All reactions