【发布时间】:2020-05-03 16:43:21
【问题描述】:
我正在开发我的第一个游戏应用程序。
我想要做的是将 GreenF 传递给 Green 组件。
但状态不会改变。我需要在函数 play() 中随时更改 GreenF;
这只是我的代码的开始,所以没有什么是完整的,只是为了你的理解。
import React, {Component} from 'react';
import {StyleSheet, Text, View,TouchableOpacity, Button} from 'react-native';
import Green from './components/Green.js'
constructor (props){
super(props);
this.state = {
greenF: false,
score: 0,
seq: [1,2,3,1,4],
playerSeq: [],
round: 1,
}
}
play() {
this.setState({ greenF: true });
}
render(){
return (
<View>
<Button
title='start'
color='black'
onPress={this.play}>
</Button>
<Green greenFlash={this.state.greenF}> </Green>
</View>
);
}
}
【问题讨论】:
-
也请发布您的
play()功能。 -
提交整个代码。谈论一个功能,但不分享功能本身。我们怎么知道你的功能?
-
刚刚更新了一个代码,对我的问题有更多解释,对不起
标签: javascript reactjs react-native environment-variables