siva-kannan3 / module-federation-vite-example

Module federation with vite
5 stars 3 forks source link

React hooks not working in remote app #1

Open Mukhametvaleev opened 2 years ago

Mukhametvaleev commented 2 years ago

Thank you Siva for example project! I just tried to replace remote/src/Components/Button/Button.jsx component with:

import {useState} from "react";

export function Button() {
  const [counter, setCounter] = useState(0);

  return (
    <button onClick={() => setCounter(counter + 1)}>
      Counter value: {counter}
    </button>
  );
}

... and I've got an error: Uncaught TypeError: Cannot read properties of null (reading 'useState')

image
siva-kannan3 commented 2 years ago

Hi @Mukhametvaleev , If you use class based components it will working fine, but with functional components & using react hooks seems behaving wrong, I am working on this issue, I will let you know If I found a fix.

mariojfduarte commented 1 year ago

facing same issue