0
Iちょうどたいここに私のコードだ..私は他のクラスからthis.state.sampleStringにアクセスする方法を尋ねる[リアクトネイティブ]
class MainClass extends Component {
constructor(props){
super(props)
this.state = {
sampleString: 'Test String'
}
this.getValue = this.getValue.bind(this);
}
getValue(){
//console.log(this.state.sampleString);
return this.state.sampleString
}
}
======= ==
これは私の第二のクラスから私の機能は、それが「未定義」を返しなぜ
function getValueFromMainClass() {
var stringFromClassHeader =() => {HeaderWithBg.getValue()}
console.log(stringFromClassHeader.sampleString);
}
MainClass
から「this.state。sampleString」の値を取得するのですか?ありがとう。私は反応したネイティブで新しい。
私にサンプルコードを教えてもらえますか?私はネイティブに反応するために新しい..ありがとう! –
答えを更新します。 –
ありがとうございました! :) –