0

그래서 필자는 this 튜토리얼을 따라 내가 필요한 것을 적용했습니다.네이티브, 리펙트 네비게이션 통합 문제가 정의되지 않았습니다. 객체가 아닙니다. getStateForAction

다른 답변을 확인했지만 누락 된 부분을 확실히 확인할 수 없습니까? 검색 엔진

는 오류 : 미정 오브젝트 라우터 아니다

enter image description here

App.js

import React, {Component} from 'react'; 
import {createStore, combineReducers, applyMiddleware} from 'redux' 
import {Provider, connect} from 'react-redux' 
import reducers from './reducers' 
import {View} from 'react-native' 


import ReduxNavigation from './components/Navigation/ReduxNavigation' 

const initialState = ReduxNavigation.router.getStateForAction(ReduxNavigation.router.getActionForPathAndParams('AddItems')); 

const navReducer = (state = initialState, action) => { 

    const newState = ReduxNavigation.router.getStateForAction(action, state) 
    return newState || state 
} 

const store = createStore(
    combineReducers({ 
     ...reducers, 
     nav: navReducer, 
    }) 
) 

export default class App extends Component { 
    render() { 
     return (
      <Provider store={store}> 
        <ReduxNavigation/> 
      </Provider> 
     ) 
    } 

} 

ReduxNavigation getStateForAction

:

import React from 'react' 
import * as ReactNavigation from 'react-navigation' 
import { connect } from 'react-redux' 
import PrimaryNav from './PrimaryNav' 

// here is our redux-aware our smart component 
function ReduxNavigation (props) { 
    const { dispatch, nav } = props 
    const navigation = ReactNavigation.addNavigationHelpers({ 
     dispatch, 
     state: nav 
    }) 

    return <PrimaryNav navigation={navigation} /> 
} 

const mapStateToProps = state => ({ nav: state.nav }) 
export default connect(mapStateToProps)(ReduxNavigation) 

PrimaryNav :

import React from 'react' 
import {StackNavigator, DrawerNavigator} from 'react-navigation' 
import AddItemsWrapper from '../AddItemsWrapper' 
import {Text} from 'react-native' 

const noTransitionConfig =() => ({ 
    transitionSpec: { 
     duration: 0, 
     timing: Animated.timing, 
     easing: Easing.step0 
    } 
}) 

const DrawerStack = DrawerNavigator({ 
    screen: {screen: AddItemsWrapper} 
}, { 
    gesturesEnabled: false, 
}) 

const drawerButton = (navigation) => 
    <Text 
     style={{padding: 5, color: 'white'}} 
     onPress={() => { 
      // Coming soon: navigation.navigate('DrawerToggle') 
      // https://github.com/react-community/react-navigation/pull/2492 
      if (navigation.state.index === 0) { 
       navigation.navigate('DrawerOpen') 
      } else { 
       navigation.navigate('DrawerClose') 
      } 
     } 
     }>Menu</Text> 

const DrawerNavigation = StackNavigator({ 
    DrawerStack: {screen: DrawerStack} 
}, { 
    headerMode: 'float', 
    navigationOptions: ({navigation}) => ({ 
     headerStyle: {backgroundColor: '#4C3E54'}, 
     title: 'Welcome!', 
     headerTintColor: 'white', 
     gesturesEnabled: false, 
     headerLeft: drawerButton(navigation) 
    }) 
}) 

// Manifest of possible screens 
const PrimaryNav = StackNavigator({ 
    drawerStack: { screen: DrawerNavigation } 
}, { 
    // Default config for all screens 
    headerMode: 'none', 
    title: 'Main', 
    initialRouteName: 'loginStack', 
    transitionConfig: noTransitionConfig 
}) 

export default PrimaryNav 
+1

추측. App 클래스 render에서'View'를 제거하고'Provider'의'ReduxNavigation' 직접 자식을 만들 수 있습니까? – bennygenel

+0

네! 영향을주지 않습니다. –

+1

반응 탐색 문서에는'initialState' 생성이 있습니다. 어쩌면 당신이 그것을 놓치고 있기 때문에. [this] (https://reactnavigation.org/docs/guides/redux#Redux-Integration)를 확인하십시오. – bennygenel

답변

1

그래서 실제로는 App.js의 대답은 Redux보다 일반 탐색 요소에서 navReducer를 빌드해야합니다. 의견을 통해 도움을 주신 benneygennel에게 감사드립니다. 그래서이 :

const navReducer = (state, action) => { 

    const newState = ReduxNavigation.router.getStateForAction(action, state) 
    return newState || state 
} 

가된다 :

const navReducer = (state, action) => { 

    const newState = PrimaryNav.router.getStateForAction(action, state) 
    return newState || state 
}