使用React Native和react-native-router-flux与redux,我有一个 Action 创建者,在里面我尝试使用Actions.key,在本例中为Actions.home,但它不起作用。我可能做错了什么?
这是我的 Action 创建者:
import * as actionTypes from './actionTypes'
import { Actions } from 'react-native-router-flux'
export const navigateHome = (text) => {
Actions.home //This does not work for some reason
return {
type: actionTypes.NAVIGATE_HOME_SUCCESS,
}
}
还有我的家<Scene/>
设置如下:
const RouterWithRedux = connect()(Router)
const store = configureStore()
export default class App extends Component {
render() {
return (
<Provider store={store}>
<RouterWithRedux>
<Scene key='root'>
<Scene component={Login} initial={true} key='login' title='Login'/>
<Scene component={Home} key='home' title='Home' type={ActionConst.REPLACE}/>
</Scene>
</RouterWithRedux>
</Provider>
)
}
}
但是当我使用 <Text onPress={Actions.home}>Continue</Text>
在组件内部进行测试时,它导航到 <Home/>
美好的。
最佳答案
您需要在 navigateHome
中调用 Actions.home()
,您不能在没有 () 的情况下只执行
.Actions.home
关于javascript - React Native/Redux 和react-native-router-flux : Why doesn't Actions. Action 创建者内部的关键工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39635383/