Я пытаюсь заставить мой текст-заполнитель уйти в onFocus в компоненте React Native TextInput. Функция вызывается и состояние меняется, но заполнитель остается. Вот код компонента:
import React from 'react';
import { View, Text, TextInput, StyleSheet } from 'react-native';
export class GeneralInput extends React.Component {
constructor(props) {
super(props);
this.state = {
placeholder: this.props.placeholder
};
}
whenInputIsFocused() {
console.log('Before changing the state');
this.state.placeholder = "";
console.log('After changing the state');
console.log(this.state);
}
render() {
console.log(this.state);
return(
<View style={styles.outerContainer}>
<Text style={styles.labelText}>{this.props.labelText}</Text>
<TextInput autoCapitalize='none' secureTextEntry={this.props.secureTextEntry} onFocus={this.whenInputIsFocused.bind(this)} underlineColorAndroid="transparent" keyboardType={this.props.type} returnKeyType={this.props.returnKeyType} placeholder={this.state.placeholder} placeholderTextColor='rgba(255, 255, 255, 0.3)' style={styles.inputStyles} />
</View>
);
}
}
Вот вывод журнала консоли:
[09:39:18] Before changing the state
[09:39:18] After changing the state
[09:39:18] Object {
[09:39:18] "placeholder": "",
[09:39:18] }
Почему мой заполнитель TextInput не исчезает, даже если функция вызывается и состояние обновляется?