vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Can't render component with hooks

Open julianblanco00 opened this issue 2 years ago • 4 comments

Versions

  • vite-plugin-federation: v.1.1.11
  • vite: v3.2.3
  • react: v17.0.2

This is my shared component export default defineConfig({ plugins: [ react(), federation({ name: 'shared-chat', filename: 'remoteEntry.js', exposes: { './Chat': './src/App.tsx', }, shared: ['react', 'react-dom'] }) ], build: { target: 'esnext', minify: false, cssCodeSplit: false } })

And this is my host: export default defineConfig({ plugins: [ react(), federation({ name: "app1", remotes: { 'shared-chat': "http://127.0.0.1:4173/assets/remoteEntry.js" }, shared: ['react', 'react-dom'] }), ], });

I can't render a component/context if it has a hook. The exported component is written in TS.

julianblanco00 avatar Nov 11 '22 14:11 julianblanco00

i have the same problem, i can't export my shared component with context api

image

AdrianAmerico avatar Dec 05 '22 12:12 AdrianAmerico

Maybe you are using something like import { useContext } from 'react'? If this is the case, i think this is the problem. At the moment (as far as i know), the plugin has a problem with this. You have to use React.useContext... :/

UrielJavier avatar Feb 20 '23 22:02 UrielJavier

This problem still exists with the latest version. Basically makes it unusable with React applications.

mahammedzkhan avatar Mar 24 '23 10:03 mahammedzkhan

Same problem here. What's the point if you can't use the most basic functionality of React with this?

billdwhite avatar Sep 15 '23 21:09 billdwhite