vite-plugin-federation
vite-plugin-federation copied to clipboard
Can't render component with hooks
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.
i have the same problem, i can't export my shared component with context api
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... :/
This problem still exists with the latest version. Basically makes it unusable with React applications.
Same problem here. What's the point if you can't use the most basic functionality of React with this?