jherr / practical-module-federation-20

Code for Practical Module Federation 2.x
29 stars 15 forks source link

State Share - Use Context Example #2

Closed NickCain closed 2 years ago

NickCain commented 2 years ago

Hi,

Firstly, thank you for all of these examples for MFEs and webpacks modules federation, the book and these examples have helped alot during my development.

I have a query regarding the Use Context Example: https://github.com/jherr/practical-module-federation-20/tree/main/part1-getting-started/state-sharing/use-context

I have pulled down this example and run the project and tried the example, however I can only see the context state updating in the host, and not in the nav project.

For example, when clicking the button to increase the count, it updates the in the host app, however when i go to the nav app in running on the localhost:3001 it still appears to be 0.

My assumption would be that this value is also updated to the same count value as these two should be in sync? Am I right with this assumption?

Any help or guidance on this is appreciated.

Thanks in advance.

jherr commented 2 years ago

You are wrong in your assumption. Federated modules are just run on the client. They aren't running in some special context. It's just shared code, not shared state. If you want more details on this misconception, and a couple more, watch this: https://youtu.be/0WIFW3s2fDM

NickCain commented 2 years ago

Thank you @jherr for getting back to me and thanks for the video will give it a watch.