CharlesStover/reactn

Don't export functions with the same name as common React hooks

m4ttheweric opened this issue · 1 comments

Hi!

This is more of a quality of life request/issue. But I have found a number of times when using the standard React hooks in a new module, I will often mistakenly import useState/useContext/useMemo from reactn without meaning to because they show up first in the IntelliSense, right above the React hooks. I honestly am not sure what these are for, as I haven't used them before. But if it makes sense, can they be renamed or not exported?

The import statement from 'react' vs from 'reactn' looks so dang similar that sometimes I don't notice it and I am afraid there could be weird effects if I ever missed it!

Thanks!

Matt

These are the same hooks as from React. I believe you are getting this behavior because the reactn package reexports React by design. You can import React from 'reactn';. This is a bit of legacy behavior that made more sense in a world before hooks. The intention here was that the Component and PureComponent classes had a global member variable and setGlobal method built in for accessing and updating the global state. Importing React made global state "just work" and was the original intention of the package.

The React builtins, outside of Component and PureComponent classes, are references to the same locations in memory as those from the react package. You should not experience any behavioral differences.

I cannot change this behavior as it would be a breaking change for those importing React from the package. This may be an issue for which Intellisense can improve.