एक अधिक सामान्य समाधान के लिए डैनियल जवाब पर में सुधार
class TextInput2 extends Component {
constructor(props) {
super(props);
this.state = { placeholder: props.text.length == 0 }
this.handleChange = this.handleChange.bind(this);
}
handleChange(ev) {
this.setState({ placeholder: ev.nativeEvent.text.length == 0 });
this.props.onChange && this.props.onChange(ev);
}
render() {
const { placeholderStyle, style, onChange, ...rest } = this.props;
return <TextInput
{...rest}
onChange={this.handleChange}
style={this.state.placeholder ? [style, placeholderStyle] : style}
/>
}
}
उपयोग:
<TextInput2
text={this.state.myText}
style={{ fontFamily: "MyFont" }}
placeholderStyle={{ fontFamily: "AnotherFont", borderColor: 'red' }}
/>
स्रोत
2016-09-29 07:33:34
के लिए संपत्ति सेट कर सकते हैं? –
नहीं। एक समाधान –
अच्छी तरह से ढूंढने में प्रसन्नता होगी .. अब मैं भी एक ही समस्या से फंस गया हूं .. –