问题:
render界面渲染时候onPress指向的doSomething方法就执行了;
期望:
只有当点击这个按钮时才触发doSomething方法
<Button
...
onPress={
this.doSomething()}
...
>
原因:
猜想是RN会把{}中的对象或者方法都预加载,所以导致一进来就会被执行
解决办法:
使用箭头函数
<Button
...
onPress={
() => this.doSomething()}
...
>