我是新来的反应者。 例如,输入值输入1,2,3,4,并且在onChange事件发生后,它只需要输入数字,那么我可以 删除带有退格键的4,3,2而不是1。而且在HTML DOM中,也不能删除1。
class House extends Component {
state = {
room: null,
};
componentDidMount() {
if (this.props.house.rent) {
this.setState({ rent: this.props.house.rent });
}
}
onChange = (field, value, mutate) => {
if (field === "houseroom") {
value = parseInt(value.replace(/[@,]/g, ""));
}
mutate({
variables: {
},
});
this.setState({
[field]: value,
});
};
render(){
const {house} = this.props;
<SomeInput
type="text"
value={
(house.room&&
`$${house.room.toLocaleString("en")}`) ||
""
}
onChange={e => {
e.target.placeholder = "Room";
this.onChange("houseroom", e.target.value, mutate);
}}
}
/>
}
答案 0 :(得分:0)
状态更新过程中似乎存在很多问题,可能是由于组件中其他地方的渲染过度导致尝试使用prevState来确保状态更新不会发生冲突。
def example(one, two, *three, *four):
#three and four are lists
与我保持联系。
答案 1 :(得分:0)
希望这对某人有帮助! 需要在输入值中提及“ this.state.room”,并使用componentDidUpdate检查上一个状态,然后在此处使用“ this.setState”,最后在事件更改期间检查“ this.setState”。谢谢大家