Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 添加属性,直到处于react本机状态的react本机倒计时组件_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 添加属性,直到处于react本机状态的react本机倒计时组件

Javascript 添加属性,直到处于react本机状态的react本机倒计时组件,javascript,reactjs,react-native,Javascript,Reactjs,React Native,在react native countdown组件中之前,我在向属性添加state值时遇到问题。我已经用null声明了waktu,然后从fetch data api设置变量waktu。当我运行控制台记录状态时,该值在setState显示值之后的3次显示为null 然后,我将组件倒计时设置为变量状态,直到由null读取的值,而不是来自api的数据。我怎样才能解决这个问题?当屏幕出现时,倒计时将播放数据值not null。这是我的密码 import React,{Component}来自'Reac

在react native countdown组件中之前,我在向属性添加state值时遇到问题。我已经用null声明了waktu,然后从fetch data api设置变量waktu。当我运行控制台记录状态时,该值在setState显示值之后的3次显示为null

然后,我将组件倒计时设置为变量状态,直到由null读取的值,而不是来自api的数据。我怎样才能解决这个问题?当屏幕出现时,倒计时将播放数据值not null。这是我的密码

import React,{Component}来自'React';
从“react native”导入{View、Text、AsyncStorage、ScrollView、TouchableOpacity、Image、Dimensions、StyleSheet};
从“本机基础”导入{容器、内容、标题、左、右、按钮、图标}
从“react native HTMLView”导入HTMLView
从“反应本机倒计时组件”导入倒计时;
从“../components/Footers”导入页脚
const{width,height}=Dimensions.get('window')
导出默认类试用扩展组件{
建造师(道具){
超级(道具);
此.state={
getToken:null,
getNama:null,
soal:[],
TotalSoal:null,
索引:0,
贾瓦班:[],
indexJawaban:0,
terjawab:[],
indexTerjawab:0,
值:“”,
to_id:null,
to_nilai:null,
id_jawab:null,
//waktu:null
};
}
陈述={
瓦克图:0
}
componentDidMount=async()=>{
const nilai=await AsyncStorage.getItem('token')
this.setState({getToken:nilai})
取('https://api.bintangpelajar.com/api/user/profile_data',{
方法:'post',
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”
},
正文:JSON.stringify({
代币:尼莱
})
}).then(response=>response.json())
.然后(responseJson=>{
if(responseJson){
this.setState({getNama:responseJson.data.damping_nama})
}否则{
console.log('ada yang salah')
}
}).catch(错误=>{
console.log(错误)
})
this.getSoal()
//这是我的名字
}
getSoal=()=>{
取('http://unnamed48.ccug.gunadarma.ac.id:9091/api/user/soal',{
方法:'post',
标题:{
“接受”:“应用程序/json”,
“内容类型”:“应用程序/json”
},
正文:JSON.stringify({
令牌:this.state.getToken,
研究:“南联盟”
})
}).then(res=>res.json())
。然后(getData=>{
//console.log(getData.time)
如果(获取数据){
这是我的国家({
soal:getData.data,
TotalSoal:getData.count,
to_id:getData.to_id,
to_nilai:getData.to_nilai,
id_jawab:getData.id_jawab,
waktu:getData.time
})
for(设i=0;i{
console.log(错误)
})
}
提交JAWAB(索引、编号、id_soal、jawaban){
//警报('indeks ke-'+索引)
常数coba={
不,不,
id_soal:id_soal,
贾瓦班:贾瓦班
}
if(this.state.jawaban[index]==未定义){
this.state.jawaban.splice(索引,0,coba)
this.setState((状态)=>{
const terBaru=[…state.terjawab]
terBaru[index]=jawaban
返回{terjawab:terBaru}
})
}否则{
this.setState((状态)=>{
const jawabBaru=[…state.jawaban]
贾瓦巴鲁[指数]=coba
返回{jawaban:jawabBaru}
})
this.setState((状态)=>{
const terBaru=[…state.terjawab]
terBaru[index]=jawaban
返回{terjawab:terBaru}
})
}
}
cek=()=>{
警报('jawabannya:'+JSON.stringify(this.state.jawaban))
log(JSON.stringify(this.state.jawaban))
}
下一步行动(索引、编号、身份证){
这是我的国家({
索引:(this.state.index+1)%this.state.soal.length,
indexJawaban:(this.state.indexJawaban+1)%this.state.jawaban.length,
indexTerjawab:(this.state.indexTerjawab+1)%this.state.terjawab.length,
})
}
prevSoal=()=>{
这是我的国家({
索引:(this.state.index-1)%this.state.soal.length,
indexJawaban:(this.state.indexJawaban-1)%this.state.jawaban.length,
indexTerjawab:(this.state.indexTerjawab-1)%this.state.terjawab.length,
})
}
render(){
//变量时间=this.state.waktu*60
const{waktu}=this.state
const item=this.state.soal[this.state.index]
常数a=项目和项目.soal_opsi_a
常数b=项目和项目.soal_opsi_b
常数c=项目和项目.soal_opsi_c
const d=项目和项目.soal_opsi_d
常数e=项目和项目.soal_opsi_e
常量编号=this.state.index+1
const-id\u-soal=item&&item.soal\u-id
const jawaban=[]
console.log(waktu)
//jawaban.拼接(0,0,a,b,c,d,e)
拼接(0,0,{pg:'A',ket:A},{pg:'B',ket:B},{pg:'C',ket:C},{pg:'D',ket:D},{pg:'E',ket:E})
返回(
this.props.navigation.goBack()}>
肯巴里
Halo,{this.state.getNama}
{/*a onPress={()=>this.props.navigation.navigate('edit')}*/}