gpt4 book ai didi

ios - React-native组件的componentDidMount()在NavigatorIOS下没有被调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:04 24 4
gpt4 key购买 nike

我在结构下创建了一个带有 ListView 的组件:TabBarIOS > NavigatorIOS > ListView。我尝试在 componentDidMount() 中获取数据。但它不起作用,除非我在 componentWillMount() 中获取它。为什么?

我把我的工作放在这里https://github.com/chiakie/MyAwesomeProject
MotorcycleList.js 中,componentDidMount() 似乎从未被调用。

最佳答案

componentWillMount() 生命周期事件实际上是调用 fetchData() 的正确位置,因为它在组件安装之前被调用一次,这样你就可以 setState 做到数据在挂载时就在那里。

Mounting: componentWillMount

void componentWillMount()

Invoked once, both on the client and server, immediately before the initial rendering occurs. If you call setState within this method,render() will see the updated state and will be executed only once despite the state change.

componentDidMount() 在组件已经挂载之后呈现。

Mounting: componentDidMount

void componentDidMount()

Invoked once, only on the client (not on the server), immediately after the initial rendering occurs. At this point in the lifecycle, you can access any refs to your children (e.g., to access the underlying DOM representation). The componentDidMount() method of child components is invoked before that of parent components.

关于ios - React-native组件的componentDidMount()在NavigatorIOS下没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34393109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com