
v4.5.0 built from master branch
The development team recently bumped Web Chat's React dependency to v16.8.6 which introduces React Hooks to Web Chat. While working on a pull request for the typing indicator, I tried to use the useState and useEffect hooks in a component; however, Web Chat threw an "Invalid Hook" Error. I created a really simple component to double check it wasn't my logic, but Web Chat still threw the error.
Add a simple component with React Hooks to Web Chat.
```javascript
const TypingIndicator = () => {
const [item] = useState('Hello, World!');
return
React Hooks should not cause Web Chat to crash.
[Bug]
After some investigations, the core reason is, Webpack doesn't play well with npm link (via lerna), thus, multiple copies of react are being loaded. And React hooks doesn't like multiple copies of React.
react and react-dom in bundle as dependencies in any case (we are component package, should never bring the framework)react and react-dom as peer dependencies and requires the application to include themreact in the root package. The root package contains all devDependencies which is similar to "manually hoisted packages"[email protected] vs. babel@6, and lerna prefer 6, which broke Jest because it use the bridgereact in playground as wellplayground tried to load two copies of Reactreact from root /node_modulesreact under /packages/playground/node_modulesSome package dependencies cleanup is needed to enable React hooks in a monorepo with both component and app. It's a known issue across the community.
Most helpful comment
After some investigations, the core reason is, Webpack doesn't play well with
npm link(vialerna), thus, multiple copies ofreactare being loaded. And React hooks doesn't like multiple copies of React.reactandreact-dominbundleas dependencies in any case (we are component package, should never bring the framework)reactandreact-domas peer dependencies and requires the application to include themreactin the root package. The root package contains alldevDependencieswhich is similar to "manually hoisted packages"[email protected]vs.babel@6, and lerna prefer6, which broke Jest because it use the bridgereactinplaygroundas wellplaygroundtried to load two copies of Reactreactfrom root/node_modulesreactunder/packages/playground/node_modulesSome package dependencies cleanup is needed to enable React hooks in a monorepo with both component and app. It's a known issue across the community.