Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 状态更改后未更新容器/组件_Javascript_Ios_Reactjs_React Native_Redux - Fatal编程技术网

Javascript 状态更改后未更新容器/组件

Javascript 状态更改后未更新容器/组件,javascript,ios,reactjs,react-native,redux,Javascript,Ios,Reactjs,React Native,Redux,我一直在努力将Redux集成到我的React原生应用程序中。我在获取异步数据库获取以更新必要的组件方面遇到了困难 我可以看到数据库调用正在获取数据,并且它正确地返回状态(使用redux logger检查)。但是,我对的检查是fetching为false,不会在容器中计算。我认为我是如何声明mapstatetops方法没有触发更新的 我已经检查过我没有在我的减速机中改变状态 更新: export default class App extends Component { constructor

我一直在努力将Redux集成到我的React原生应用程序中。我在获取异步数据库获取以更新必要的组件方面遇到了困难

我可以看到数据库调用正在获取数据,并且它正确地返回状态(使用
redux logger
检查)。但是,我对
的检查是fetching
为false,不会在容器中计算。我认为我是如何声明
mapstatetops
方法没有触发更新的

我已经检查过我没有在我的减速机中改变状态

更新

export default class App extends Component {
  constructor (props) {
    super (props)
    // Load all items first.
    store.dispatch(fetchItems())
  }

  render() {
    console.log ("store.getState:")
    console.log (store.getState())
    return (
      <Provider store={store}>
        <MyApp />
      </Provider>
    );
  }
}
这似乎往往是我遗漏的看似无关紧要的部分,最终成为问题的根源。我现在明白了问题出在NavigatorIOS上。通过
passProps
传入的任何道具不会随状态一起更新。这似乎是一个众所周知的问题:

动作:

减速器:

容器:

main组件容器,该容器将项索引作为其
初始路由

class MainComponent extends Component {
  constructor(props) {
    super(props)
  }

  render() {
    const { actions, item, items, dispatch } = this.props
    console.log ("MainComponent items")
    console.log (items) // <-- this gets updated on state change
    return (
      <NavigatorIOS
        ref = "nav"
        style = {styles.navigator}
        initialRoute = {{
          passProps: { actions: actions, item: item, items: items, dispatch: dispatch },
          title: 'Items',
          component: ItemIndex
        }}
        /> 
    )
  }
}
class MainComponent扩展组件{
建造师(道具){
超级(道具)
}
render(){
const{actions,item,items,dispatch}=this.props
console.log(“主组件项”)

console.log(items)//您的操作类型匹配吗?@NaderDabit是的,它们匹配!输入错误..谢谢:)
class ItemIndex extends Component {

  constructor(props) {
    super(props);
  }

  componentWillMount() {
    console.log ("isFetching")
    console.log (this.props.items.isFetching)
  }

  render() {
    if (this.props.items.isFetching) {
      //render loading screen
      console.log ("will be loading...")
      return (
        <View/>
      )
    } else {
      console.log ("got the data") // execution never reaches here
      return (
        <Items {...this.props} />
      )
    }
  }
};

module.exports = ScaleIndex;
class MainComponent extends Component {
  constructor(props) {
    super(props)
  }

  render() {
    const { actions, item, items, dispatch } = this.props
    console.log ("MainComponent items")
    console.log (items) // <-- this gets updated on state change
    return (
      <NavigatorIOS
        ref = "nav"
        style = {styles.navigator}
        initialRoute = {{
          passProps: { actions: actions, item: item, items: items, dispatch: dispatch },
          title: 'Items',
          component: ItemIndex
        }}
        /> 
    )
  }
}
export default class App extends Component {
  constructor (props) {
    super (props)
    // Load all items first.
    store.dispatch(fetchItems())
  }

  render() {
    console.log ("store.getState:")
    console.log (store.getState())
    return (
      <Provider store={store}>
        <MyApp />
      </Provider>
    );
  }
}