调试渲染react-native IOS崩溃的位置

时间:2015-05-18 14:49:00

标签: iphone xcode react-native

当我调用this.setState时,调用render()函数。

如果渲染函数出现问题,则this.seState永远不会完成。我怎样才能找出错误在render()中的位置?

我做了

console.log('before set state');
this.setState({isLoaded:true});
console.log('after set state');

我看到第一个控制台提到打印,但不是最后一个。但是,在iOS模拟器中没有警告或错误或任何东西。我可以通过从render()一次删除一行并查看它何时停止崩溃来找到错误 - 但必须有更好的方法来调试它。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

setState本身调用渲染

来自docs(https://facebook.github.io/react/docs/component-api.html):

  

除非有条件,否则setState()将始终触发重新渲染   渲染逻辑在shouldComponentUpdate()

中实现