dai-shi / use-context-selector

React useContextSelector hook in userland
https://www.npmjs.com/package/use-context-selector
MIT License
2.68k stars 61 forks source link

"useContextSelector requires special context" warning is never printed #94

Closed srmagura closed 1 year ago

srmagura commented 2 years ago

This code is intended to print a warning if you use createContext from react rather than use-context-selector. I made this mistake and the warning was not printed. This happens because typeof process is expected to be 'undefined' when running in the browser. Going to submit a PR for this.

https://github.com/dai-shi/use-context-selector/blob/06a2c827bb19654c44952f098ba8e1fc4807e645/src/index.ts#L159-L163

dai-shi commented 2 years ago

Good point. So, you use some bundlers (vite?) that injects process.env.NODE_ENV but not process, right?

srmagura commented 2 years ago

Yes, that is correct. I am using Webpack which replaces process.env.NODE_ENV but does not actually define a process object.

dai-shi commented 1 year ago

I have been thinking about this, also in another project, but the current way is fairly safe. I wish there were a standard way in the source code that works for CJS, ESM, browser and Deno. Until we know same good way, let's leave it.

For now, please configure your webpack to define process as {} in development mode.

Closing.