New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React hooks composition fail when packaging into different entries #15605
Comments
May be I‘m doing something wrong and need read some docs. Please help navigate to right articles for improve understanding of the problem. Now I’m really disoriented |
I don't think this is webpack problem.. please ask in react issue tracker. |
@vankop okay. Ask I guess it's not a problem. I just need configure webpack right. But don't know how now. I decide to continue in gitter. Is it a right communication channel with community?. Or another one (which) is more suitable channel? this - https://gitter.im/webpack/webpack?at=624598776b912423205dd681 |
so maybe you just need to add both entrypoints on the page? ( you need to use |
@vankop this a problem, because i build a library, not a page. But i already tried dependOn :) How i do it right inside library? I try use dependOn. But it crash library loading in ui application
I can't finish variant with dependOn because lack of knowledge about how cook it right :) May be you can advice something? |
For explanation i have three files
For the output i need one shared file - contexts.js , (because react hook useContext check similarity via reference). |
but what a reason to create a separate entries? just use your app entrypoint |
@vankop main reason is libraries and code which not support SSR. For example: But i can't use useCall. useCall depend on libraries who use window as global var. When import from external libraries like this it produce import fail. Component like this, should be decorated with dynamic import (example) I want to save ability to use some hooks without dynamic imports. |
Bug report
What is the current behavior?
React hook
useContext(Context)
doesn't work when call from another hook from different entryFor example:
useHook1
anduseHook2
.useHook2
calluseHook1
inside/src/usr-hook1
and /src/usr-hook2` for some reasonResult:
useHook1
- return right value in ComponentuseHook1
inside useHook2 return undefined <-- problem hereIf the current behavior is a bug, please provide the steps to reproduce.
Reproducible example - react-hooks-composition-in-webpack-entry-problem-example
npm i
npm run all:start
ornpm run sdk:dev
and thennpm run ui:dev
in different terminalWhat is the expected behavior?
useHook1
return right value insideuseHook2
. (In example project names is different, follow code)Other relevant information:
webpack version: 4.7.0
Node.js version: 16
Operating System: OSX/Windows 11 WSL Ubuntu
Additional tools: next.js 12.1.3
The text was updated successfully, but these errors were encountered: