Ho problemi con il bind del valore di un input, l'ho fatto su un altro componente della mia app e ha funzionato bene, ma in qualche modo non riesco a farlo funzionare su un altro componente. Sto ottenendo soltanto la prima lettera e non l'intero testoReact, Binding input values
Questa è la mia componente
class Post extends Component {
constructor(props) {
super(props);
this.state = {
post: this.props.data,
comment: ''
}
Post.context = this;
}
render() {
<input type="text" value={this.state.comment} onChange={this.handleChange} placeholder="Write a comment..." />
<button className="button comments" onClick={this.handleClick.bind(null,this.state.post.id)}></button>
}
handleChange(e) {
Post.context.setState({comment: e.target.value});
}
}
Ho anche cercato di usare un esempio da Reagire sito ma ha ottenuto lo stesso risultato:
render() {
var valueLink = {
value: this.state.comment,
requestChange: this.handleChange
};
render() {
<input type="text" valueLink={valueLink} placeholder="Write a comment..." />
<button className="button comments" onClick={this.handleClick.bind(null,this.state.post.id)}></button>
}
handleChange(newValue) {
Post.context.setState({comment: newValue});
}
}
Qualcuno ha idea, perché questo sta accadendo?
ovviamente !! ha funzionato bello! Grazie compagno!! –