Reactjs 反应设置状态不在键盘上工作?
我有一个像这样的简单函数,我只是从react文档中复制了它,警报工作得很好,但是我的函数Reactjs 反应设置状态不在键盘上工作?,reactjs,react-native,Reactjs,React Native,我有一个像这样的简单函数,我只是从react文档中复制了它,警报工作得很好,但是我的函数changescription什么都不做,即使我放了一个简单的setstate??我做错了什么 constructor(props) { super(props); this.changeDescription = this.changeDescription.bind(this); this.sendDescription = this.sendDescription.bind
changescription
什么都不做,即使我放了一个简单的setstate??我做错了什么
constructor(props) {
super(props);
this.changeDescription = this.changeDescription.bind(this);
this.sendDescription = this.sendDescription.bind(this);
this._keyboardDidHide = this._keyboardDidHide.bind(this);
}
componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener(
'keyboardDidShow',
this._keyboardDidShow,
);
this.keyboardDidHideListener = Keyboard.addListener(
'keyboardDidHide',
this._keyboardDidHide,
);
}
componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
_keyboardDidHide() {
const { member } = this.props;
alert(member.description)
this.changeDescription('ok')
}
changeDescription = (val) => {
// console.log(val)
this.setState({ description: val })
}
<Textarea
defaultValue={member.description}
onChangeText={v => this.changeDescription(v)}
/>
构造函数(道具){
超级(道具);
this.changescription=this.changescription.bind(this);
this.sendDescription=this.sendDescription.bind(this);
this.\u keyboardidhide=this.\u keyboardidhide.bind(this);
}
componentDidMount(){
this.keyboardDidShowListener=Keyboard.addListener(
“keyboardDidShow”,
这是键盘显示,
);
this.keyboardDidHideListener=Keyboard.addListener(
“键盘隐藏”,
这是我的键盘,
);
}
组件将卸载(){
this.keyboardDidShowListener.remove();
this.keyboardidHidelistener.remove();
}
_键盘隐藏(){
const{member}=this.props;
警报(成员说明)
this.changeDescription('ok'))
}
changeDescription=(val)=>{
//console.log(val)
this.setState({description:val})
}
此.changescription(v)}
/>
我猜您只需要设置Textarea的值
<Textarea
defaultValue={member.description}
onChangeText={v => this.changeDescription(v)}
value={this.state.description} />
this.changescription(v)}
值={this.state.description}/>
我猜您只需要设置Textarea的值
<Textarea
defaultValue={member.description}
onChangeText={v => this.changeDescription(v)}
value={this.state.description} />
this.changescription(v)}
值={this.state.description}/>
您从哪里获得Textarea组件?基本上是nativebase。TextInput您可以在使用描述状态的地方共享代码吗?我看到了状态的设置,但没有使用。执行this.setState({description:val})时,不清楚您期望发生什么它在textarea上?你从哪里得到textarea组件?nativebase基本上是。TextInput你能在使用描述状态的地方共享代码吗?我看到状态的设置,但没有使用。不清楚执行时会发生什么:this.setState({description:val}它在文本区域?谢谢你知道正确的语法:onChangeText={v=>this.changescription(v)}{this.state.description?value={this.state.description}:null}如果我想根据描述是否为空来呈现值,默认值应该为您处理。不是吗?是的,但是我如何才能恢复到默认值谢谢您知道:onChangeText={v=>this.changescription(v)}{this.state.description?value={this.state.description}:null}的正确语法吗如果我想根据if description if empty呈现值,默认值应该为您处理。不是吗?是的,但是我如何才能恢复到默认值