Я новичок в react native и redux и работаю над этим впервые. Я не уверен, как использовать возвращаемое значение в store.getState () в файле App. js.
console.ignoredYellowBox = ["Remote debugger"];
import { YellowBox } from "react-native";
YellowBox.ignoreWarnings([
"Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?",
]);
import React, { Component } from "react";
import { StyleSheet, Text, View, AsyncStorage } from "react-native";
import * as Font from "expo-font";
import { AppLoading } from "expo";
import AppNavigation from "./navigation/AppNavigator";
import { setNavigator } from "./navigationRef";
import userReducer from "./reducers/userReducer";
import chatReducer from "./reducers/chatReducer";
import { Provider } from "react-redux";
import { createStore, applyMiddleware, combineReducers } from "redux";
import ReduxThunk from 'redux-thunk';
import createSocketIoMiddleware from "redux-socket.io";
import io from "socket.io-client";
const store = createStore(combineReducers({userReducer, chatReducer}), applyMiddleware(ReduxThunk));
class App extends Component {
constructor(props) {
super(props);
console.log(props);
this.state = {
fontLoaded: false,
};
}
async componentWillMount(){
const response = await(store.getState().userReducer.token)
console.log("Response:", response)
}
render() {
const fetchFont = () => {
return Font.loadAsync({
"raleway-bold": require("./assets/fonts/Raleway-Bold.ttf"),
ralewayBold: require("./assets/fonts/Raleway-Bold.ttf"),
"roboto-regular": require("./assets/fonts/Roboto-Regular.ttf"),
robotoRegular: require("./assets/fonts/Roboto-Regular.ttf"),
Roboto_medium: require("./assets/fonts/Roboto-Regular.ttf"),
});
};
if (!this.state.fontLoaded) {
return (
<AppLoading
startAsync={fetchFont}
onFinish={() => this.setState({ fontLoaded: true })}
onError={(err) => {
console.log(err);
}}
/>
);
}
return (
<Provider store={store}>
<AppNavigation
ref={(navigator) => {
setNavigator(navigator);
}}
/>
</Provider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
export default App;
Я хочу получить доступ к состоянию редукции отсюда, чтобы получить доступ к хранящемуся там токену. Ссылаясь на несколько сообщений, я попытался использовать метод store.getState (), но когда я его console.log, я получаю null