AsyncStorage를 사용하여 setItem
을 처리 할 수 없습니다. 다음은 내 코드입니다. 그래서 저는 TextInput
에서 주에서 이름을 얻었고 AsyncStorage
에 저장하고 싶습니다. 내가 잘못AsyncStorage에서 항목을 설정할 수 없습니다.
import React, { Component } from 'react';
import { View, Text, StyleSheet, TextInput, TouchableOpacity} from 'react-native';
class AsyncStorage extends Component {
constructor(props) {
super(props);
this.state = {
name:''
}
//this.asyncSetName = this.asyncSetName.bind(this) //tried this too.
};
asyncSetName(){
let name = this.state.name
AsyncStorage.setItem('name', name);
}
render(){
<View>
<TextInput
placeholder='Set Name here'
onChangeText={(name) => this.setState({name})}
value={this.state.name}
autoCorrect={false}
></TextInput>
<TouchableOpacity
onPress={this.asyncSetName.bind(this)}
>
<Text>SetName</Text>
</TouchableOpacity>
</View>
}
}
를하고있는 중이 야 무엇을 : 나는 오류를 받고 있어요? 도와주세요.
감사합니다. 이'this.asyncSetName = this.asyncSetName.bind (this)'와 같은 생성자 (props)에서 함수를 바인드해야하며'onPress = {this.asyncSetName.bind (this)}'와 같이 호출해야합니다. 두 번 바인딩해야하는 이유는 무엇입니까? – Somename
당신은 환영합니다 ... 바인딩에 관해서는 바인딩을 한 번해야합니다, 나는 하나의 생성자를 사용하는 것을 선호합니다 –