reactReact Native

我在react native踩过的坑(持续更新...)

2016-08-29  本文已影响10839人  阿波罗程序猿

坑.js

对于这样的情况,请设置高度和宽度

1.第一步:
npm install --save react-native@latest
2.第二步:
nam install

npm install --save react@15.2.1

大体意思就是在render这种需要props和state进行渲染的方法中,不能再对props和state进行更新。我的理解是,React会在props和state改变的时候调用 render进行DOM diff然后渲染,如果在渲染过程中再对props和states进行更改,就陷入死循环了。
例如:
<Button onPress={hideMessage('隐藏信息')}>隐藏信息</Button>
当点击button时,就会报上述错误,因为这样会在渲染是更改组件的状态。
解决方法:
在调用方法时创建一个匿名函数,再调用。
<Button onPress={()=>{hideMessage('隐藏信息')}}>隐藏信息</Button>

当使用<Image />source属性时,从网络获取图片资源,要求设置图片的高度和宽度。FB react native文档上并没有提示这点。

Application myExample has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.

error.png

关闭上一个项目的React Packager控制台。之后再重新运行react-native run-ios

导入的类必须是大写的
import App from './src/app';正确
import app from './src/app';错误

上一篇 下一篇

猜你喜欢

热点阅读