【发布时间】:2020-02-16 21:37:15
【问题描述】:
redux 的 getState()、subscribe() 等方法没有进入我的组件,而只有初始的 store 对象进入组件的 props。我可以用它做什么来解决这个问题?
道具日志
商店:{ 待定:假, fetchFailed:假, 授权:假, 哈希:'', 用户名:'',}
App.js
import React from 'react';
import Main from './views/Main';
import Auth from './views/Auth';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import {Provider} from 'react-redux';
import initStore from './store/store';
const AppNavigator = createStackNavigator({
Main: {
screen: Main,
path: 'Main',
},
Auth: {
screen: Auth,
path: 'Auth',
},
}, {
initialRouteName: 'Auth',
defaultNavigationOptions: {
header: null,
},
});
const AppNavigationContainer = createAppContainer(AppNavigator);
const config = {
pending: false,
fetchFailed: false,
authorized: false,
hash: '',
username: '',
};
const store = initStore(config);
const App = () => {
return (
<Provider store={store}>
<AppNavigationContainer data={store} /> // Don't work data prop
</Provider>
);
};
export default App;
Store.js
import {createStore, applyMiddleware} from 'redux';
import logger from 'redux-logger';
import thunk from 'redux-thunk';
import reducer from '../reducers/reducers';
const initStore = (preloadStore) => {
const store = createStore(reducer, preloadStore, applyMiddleware(thunk, logger));
return store;
};
export default initStore;
Auth.js
// some code...
export default connect(
(store) => ({
store,
}),
(dispatch) => ({
dispatch,
}),
)(Auth);
【问题讨论】:
标签: reactjs react-native redux react-redux react-navigation