Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store.dispatch action redux from mini app to host app not working #791

Open
HongQuang231 opened this issue Nov 12, 2024 · 6 comments
Open
Labels
status:new New issue, not reviewed by the team yet. status:stale Missing feedback or response for prolonged period of time. type:bug A bug report.

Comments

@HongQuang231
Copy link

Describe the bug

i have a host app and mini app and two projects also setup redux, in the mini app, I use dispatch by useDispatch from func component .tsx, and it's working, but when i use store.dispatch() it not working. in two projects, i have a slice

Image

Image

note:

const dispatch = useAppDispatch()
dispatch(commonAction.setIsAuthorized(true)) // working

store.dispatch(commonAction.setIsAuthorized(true)) // not working

System Info

no

Re.Pack Version

4.0.0

Reproduction

c

Steps to reproduce

no

@HongQuang231 HongQuang231 added status:new New issue, not reviewed by the team yet. type:bug A bug report. labels Nov 12, 2024
@jbroma
Copy link
Member

jbroma commented Nov 12, 2024

Hey @HongQuang231, please create a reproduction repository showcasing the problem so we determine if this needs fixing or is a matter of configuration, thanks!

@HongQuang231
Copy link
Author

HongQuang231 commented Nov 13, 2024

in host app and mini app i config redux look like this:

import {configureStore} from '@reduxjs/toolkit';
import createSagaMiddleware from 'redux-saga';
import {persistStore, persistReducer} from 'redux-persist';

import reducer from './slices';
import mySaga from './sagas';
import AsyncStorage from '@react-native-async-storage/async-storage';

// create the saga middleware
const sagaMiddleware = createSagaMiddleware();

// Persist config
const persistConfig = {
key: 'root',
storage: AsyncStorage,
whitelist: ['account'], // Add reducer names you want to persist here
};

// Wrap the root reducer with persistReducer
const persistedReducer = persistReducer(persistConfig, reducer);

// mount it on the Store
const store = configureStore({
reducer: persistedReducer,
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
serializableCheck: false,
}).concat(sagaMiddleware),
});

// then run the saga
sagaMiddleware.run(mySaga);

// Create a persistor
const persistor = persistStore(store);

export type RootState = ReturnType;
export type AppDispatch = typeof store.dispatch;

export {store, persistor}; // Export persistor

two projects so i have config two store file.
I think I config it right, but the store i use in the host app and the mini app can be different, how to i can share the store config of redux from host app to the mini app,

@jbroma

@HongQuang231
Copy link
Author

i have a problem, if the mini app has accessToken expired, how can I create interceptor with fetch api in the mini app and it will direct to login in the host app

@jbroma
Copy link
Member

jbroma commented Nov 13, 2024

@HongQuang231 please create a repository with everything in place, I'm not able to dedicate enough time to recreate your example from scratch based on the code snippets you've provided.

@HongQuang231
Copy link
Author

@jbroma
https://github.com/HongQuang231/host
https://github.com/HongQuang231/mini

my repo look like this and in mini app i have 2 func

Image

I want to use store.dispatch(commonActions.setIsAuthorized(true)); in mini app, can you help me, thanks

Copy link

This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days.

@github-actions github-actions bot added the status:stale Missing feedback or response for prolonged period of time. label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:new New issue, not reviewed by the team yet. status:stale Missing feedback or response for prolonged period of time. type:bug A bug report.
Projects
None yet
Development

No branches or pull requests

2 participants