title: Custom react hook library. Webpack externals and peerDependencies doesn't work
body: <p>Each new try I getting 2 cases:</p>
  <p>&quot;Invalid hook call&quot; - because of double React environment.</p>
  <p>&quot;Can't resolve &quot;react&quot;&quot; - if I would remove it from devDependencies in hook library.</p>
  <p>Goal is : to set up correct build environment of hook library.</p>
  <p>webpack.config.js</p>
  <pre><code>const path = require(&quot;path&quot;)
  
  module.exports = {
      mode: &quot;production&quot;,
      entry: &quot;./src/index.ts&quot;,
      output: {
          filename: &quot;index.js&quot;,
          path: path.resolve(__dirname, 'dist'),
          clean: true,
          library: &quot;custom-hook-lib&quot;,
          libraryTarget: &quot;umd&quot;
      },
      externals: {
          'react': 'react',
          'react-dom' : 'reactDOM'
      },
  
      resolve: {
          extensions: [&quot;.js&quot;, &quot;.jsx&quot;, &quot;.json&quot;, &quot;.ts&quot;, &quot;.tsx&quot;]
      },
      
      module: {
          rules: [
              {
                  test: /\.(j|t)sx?$/,
                  exclude: /(node_modules)/,
                  use: 'ts-loader'
              }
          ]        
      }
      
  }
  </code></pre>
  <p>package.json</p>
  <pre><code>{
    &quot;name&quot;: &quot;custom-hook-lib&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;dist/index.js&quot;,
    &quot;module&quot;: &quot;dist/index.js&quot;,
    &quot;files&quot;: [
      &quot;dist&quot;
    ],
    &quot;keywords&quot;: [],
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;peerDependencies&quot;: {
      &quot;react&quot;: &quot;^18.2.0&quot;,
      &quot;react-dom&quot;: &quot;^18.2.0&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;react&quot;: &quot;^18.2.0&quot;,
      &quot;react-dom&quot;: &quot;^18.2.0&quot;,
      &quot;@types/react&quot;: &quot;^18.0.17&quot;,
      &quot;typescript&quot;: &quot;^4.8.2&quot;,
      &quot;webpack&quot;: &quot;^5.74.0&quot;,
      &quot;webpack-cli&quot;: &quot;^4.10.0&quot;,
      &quot;ts-loader&quot;: &quot;^9.3.1&quot;
    }
  }
  
  
  </code></pre>