javascript - React Native/Redux 和react-native-router-flux : Why doesn't Actions. Action 创建者内部的关键工作?

标签 javascript reactjs react-native redux react-redux

使用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/

相关文章:

javascript 抛出未捕获的类型错误 : Cannot set property '0' of undefined when filling multidimensional array

javascript - 处理更改事件不适用于输入类型?

reactjs - React 渲染中的解构状态

reactjs - 如何将 "save"按钮设置为山顶而不是 "new"

android - react native : Re-render component in time interval

javascript - 如何在wix react native 导航中将数据从一个屏幕传递到另一个屏幕

javascript - 样式未在组件内更新

javascript - 如何使用 ASP.NET Core 2.1 和 React JS 创建下载功能?

javascript - VeeValidate - ES5 中的自定义验证函数

reactjs - 无法解析依赖项 : peer react @"^16 || ^17" from react-top-loading-bar@2. 1.0