Skip to content

Commit

Permalink
create-context-store
Browse files Browse the repository at this point in the history
  • Loading branch information
ken88ling committed Feb 15, 2022
1 parent c9e64ab commit 3e0c46c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion host/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ module.exports = {
remotes: {
nav: 'nav@http://localhost:3001/remoteEntry.js',
},
exposes: {},
exposes: {
'./store': './src/store',
},
shared: {
...deps,
react: {
Expand Down
12 changes: 8 additions & 4 deletions nav/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { CountProvider } from 'host/store';

import Header from './Header';

import './index.css';

const App = () => (
<div className='container'>
<Header />
Name: Nav
</div>
<CountProvider>
<div className='container'>
<Header />
Name: Nav
</div>
</CountProvider>
);
ReactDOM.render(<App />, document.getElementById('app'));
7 changes: 5 additions & 2 deletions nav/src/Header.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { useCount } from 'host/store';

function Header() {
const [count, setCount] = useCount();

function Header({ count, onClear }) {
return (
<div style={{ border: '1px solid black' }}>
Header
<div>{count}</div>
<button onClick={onClear}>Clear</button>
<button onClick={() => setCount(0)}>Clear</button>
</div>
);
}
Expand Down
4 changes: 3 additions & 1 deletion nav/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module.exports = {
new ModuleFederationPlugin({
name: 'nav',
filename: 'remoteEntry.js',
remotes: {},
remotes: {
host: 'host@http://localhost:3000/remoteEntry.js',
},
exposes: { './Header': './src/Header.js' },
shared: {
...deps,
Expand Down

0 comments on commit 3e0c46c

Please sign in to comment.