Using Redux in both host app and mini app #735
Replies: 2 comments 6 replies
-
I accomplished using Redux in React-Native-Web (Re.Pack) by leveraging redux toolkit's I have one true Redux store (the global store) at the root, which is specified as a singleton instance via the ModuleFederation plugin. Mini apps maintain their own slices and expose a When any component in the So the only place where I render a Redux I have a monorepo setup (managed by Nx) and the global store exposes hooks to allow any app in the monorepo to access global store's state (e.g Mini-apps are able to successfully define their own slices, selectors and actions (all defined in their own projects), |
Beta Was this translation helpful? Give feedback.
-
What is the exact error that you see?
…On Wed, Sep 11, 2024, 1:18 a.m. Rises ***@***.***> wrote:
Hi @sahajarora1286 <https://github.com/sahajarora1286> thanks for the
details , i've updated my component with similar details
My Component that loads the *mini app* Remote component
const RemoteComponent = React.lazy(() => Federated.importModule('testApp', './App'));
const NewsScreen = () => {
const [isMiniAppLoaded, setIsMiniAppLoaded] = useState(false);
useEffect(() => {
const loadMiniAppSlice = async () => {
try {
const {default: miniSlice} = await Federated.importModule(
'testApp',
'./rootReducer',
);
injectReducer('mini', miniSlice);
setIsMiniAppLoaded(true);
} catch (error) {
console.error('Failed to load mini-app slice:', error);
}
};
loadMiniAppSlice();
}, []);
return (
<ErrorBoundary name="NewsScreen">
<React.Suspense
fallback={<Placeholder label="News and Articles" icon="newspaper" />}>
{isMiniAppLoaded && <RemoteComponent />}
</React.Suspense>
</ErrorBoundary>
);};
export default NewsScreen;
Inject Reducer in *host app*
import {configureStore, combineReducers, Reducer} from ***@***.***/toolkit';import counterReducer from './counter/counterSlice';
const staticReducers = {
counter: counterReducer,};
const store = configureStore({
reducer: staticReducers,});
export type RootState = ReturnType<typeof store.getState>;export default store;
export const injectReducer = (key: string, asyncReducer: Reducer) => {
if (!store.asyncReducers) {
store.asyncReducers = {...staticReducers};
}
if (!store.asyncReducers[key]) {
store.asyncReducers[key] = asyncReducer;
store.replaceReducer(combineReducers(store.asyncReducers));
}};
Screenshot.2024-09-11.at.10.37.56.AM.png (view on web)
<https://github.com/user-attachments/assets/aa7feb98-0be0-4d69-b388-b770a2498215>
Now when i try to load the remote bundle then i'm getting the issues
related to immer and redux , i've already added the immer and redux alias
in the host and remote app webapp.config.js files like following:-
redux: path.resolve('./node_modules/redux/dist/redux.legacy-esm.js'),
'react-redux': path.resolve(
'./node_modules/react-redux/dist/react-redux.legacy-esm.js',
),
immer: path.resolve('./node_modules/immer/dist/immer.legacy-esm.js'),
***@***.***/toolkit': path.resolve(
***@***.***/toolkit/dist/redux-toolkit.legacy-esm.js',
),
'redux-thunk': path.resolve(
'./node_modules/redux-thunk/dist/redux-thunk.legacy-esm.js',
),
—
Reply to this email directly, view it on GitHub
<#735 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADL7BCPEXNSEXHNJP2EBOBLZV7HBXAVCNFSM6AAAAABNY43JKSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANRQHE3DQMY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I have a mini app which has full functionality and it's own store using redux and redux toolkit , now i want to load into host app which is based of Super App Showcase and i'm having the following error
mini app that i want to load has following configuration.
Beta Was this translation helpful? Give feedback.
All reactions