CharlesStover / reactn

React, but with built-in global state management.
https://www.npmjs.com/package/reactn
MIT License
1.89k stars 85 forks source link

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

Closed m4ttheweric closed 4 years ago

m4ttheweric commented 4 years ago

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

quisido commented 4 years ago

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.