Я выполнил все шаги по созданию магазина, но когда я пытаюсь получить доступ к своим реквизитам, они не определены. Я использую реагирующий Native, Redux и компонент подключения из «React-Redux». Пожалуйста помоги . Я не могу двигаться вперед.
здесь я подключаю реквизиты к состоянию:
const mapStateToProps = (state) => ({
location : state.location
})
export default connect(mapStateToProps)(MapsScreen);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent:'center',
alignContent:'center',
}
})
Это компонент:
import LocationComp from './location'
import {connect} from 'react-redux';
import * as actions from '../../../redux/actions'
import MapView from 'react-native-maps';
export class MapsScreen extends React.Component {
state = {
isLoading : true
}
handleLanguage = (loco) => {
store.dispatch(actions.newLocation(loco))
this.setState({ isLoading: !this.state.isLoading })
console.log(store.getState())
}
render() {
return (
<View style = {{flex :1}}>
{this.state.isLoading === true ?
(
<LocationComp getLocation = {this.handleLanguage}/>
):(
<MapView
style={{flex:1}}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}>
{console.log(this.props.location)}
</MapView>
)}
</View>
);
}
}
Мой магазин:
import {createStore, applyMiddleware} from 'redux'
import reducer from './reducer'
import {addTest} from './actions'
import thunk from 'redux-thunk'
export default store = createStore(reducer, applyMiddleware(thunk))
Мой редуктор:
import {UPDATE_TEST, UPDATE_LOCATION,} from './actions'
import { combineReducers} from 'redux'
const merge = (prev, next ) => Object.assign({}, prev, next)
const hustleReducer = (state = [], action) => {
if(action.type === UPDATE_TEST) {
return [...state, action.payload]
}
return state
}
const locoReducer = (state = {}, action) => {
if(action.type === UPDATE_LOCATION){
return merge(state.location, action.payload)
}
return state
}
export default reducer = combineReducers({
hustleList : hustleReducer,
location : locoReducer,
})
Мои действия:
/// action creators
export const UPDATE_TEST= 'UPDATE_TEST'
export const UPDATE_LOCATION = 'UPDATE_LOCATION'
export const addTest = newContact => ({
type : UPDATE_TEST,
payload : newContact
})
export const newLocation = newLocation =>({
type : UPDATE_LOCATION,
payload : newLocation
})