It's a pain to work with react.js when it comes to form. I was from angular, because of 2 ways binding things are great, it's fast to integrate stuff. But when in react I admit I'm lost.
Says it's a user profile, I got this data from API
var profile = {
name:"Gaila",
age:22,
skills: [{id:1,name:"react"},{id:1,name:"angular"}],
club: [{id:1,name:"dancing"},{id:1,name:"hiking"}],
description: "some long string"
};
on the UI I have text input
, textarea
, checkbox
and select
.
How would I handle it when user clicked to save? Do I have to bind every single input elements with onChange? like handleNameChange, handleAgeChange, handleSkillsChange.. omg it's ridiculous.
So ref came into my mind, easy, just do ref="name"
and I can get it by ReactDOM.findDOMNode(this.refs.name).value
, but wait, it doesn't work on <select>
, it's bad sometime I use ref, sometime I go with handle function.
Guys, I seriously, really need help!