我正在使用API来获取图像URL。我能够正确获取图片网址。但有时少数图像不能渲染。React-Native:图像渲染不一致
反应原生代码有问题吗?
var productDetail = this.state.result[i];
this.state.product.push(
<View key = {i} style={{margin: 0.5, borderWidth: 10, borderColor: 'white', backgroundColor: 'white'}}>
<Image
resizeMode={'contain'}
style={{width: width/2.35, height: 180,}}
source={{uri: "https://abcd.in"+productDetail.image_url}}>
</Image>
</View>
渲染,如:
<View>
{product}
</View>
不要变异状态直接就不会导致重新呈现,使用的setState看到这个https://stackoverflow.com/问题/ 41376203 /为什么我不能在我的状态阵列中反应js/41376329#41376329 –
正如@ShubhamKhatri所说,这个问题是因为你更新你的应用程序的方式。你不应该改变状态,而应该使用setState来触发重新渲染。这就是行为不一致的原因。 –
为了扩大对我以前的评论,你将有: 'addProduct命令=()=> { this.setState({ 产品:product.concat( <查看键= {I}风格= {{保证金:0.5, borderWidth:10,borderColor:'white',backgroundColor:'white'}} ) }); }' –