So, I'm just starting to use React, and it's hard for me to collect the input values of the input data in a child component. Basically, I create various components for the large form that I create, and then in the enclosing component I want to collect all the input values for the children in the object I call, and then send the collected input to POST AJAX (you can see an example in the last component that I did). I can get the values easily enough when I'm inside the components, but pull them out of the parent component, which I did not understand.
Thanks in advance. Just relieving the pain right now with React, so any advice on how to structure it better, I'm all ears!
Here are my components:
Component 1
var StepOne = React.createClass({ getInitialState: function() { return {title: '', address: '', location: ''}; }, titleChange: function(e) { this.setState({title: e.target.value}); }, addressChange: function(e) { this.setState({address: e.target.value}); }, locationChange: function(e) { this.setState({location: e.target.value}); }, render: function() { return ( <div className="stepOne"> <ul> <li> <label>Title</label> <input type="text" value={this.state.title} onChange={this.titleChange} /> </li> <li> <label>Address</label> <input type="text" value={this.state.address} onChange={this.addressChange} /> </li> <li> <label>Location</label> <input id="location" type="text" value={this.state.location} onChange={this.locationChange} /> </li> </ul> </div> ); }, // render }); // end of component
Component second
var StepTwo = React.createClass({ getInitialState: function() { return {name: '', quantity: '', price: ''} }, nameChange: function(e) { this.setState({name: e.target.value}); }, quantityChange: function(e) { this.setState({quantity: e.target.value}); }, priceChange: function(e) { this.setState({price: e.target.value}); }, render: function() { return ( <div> <div className="name-section"> <div className="add"> <ul> <li> <label>Ticket Name</label> <input id="name" type="text" value={this.state.ticket_name} onChange={this.nameChange} /> </li> <li> <label>Quantity Available</label> <input id="quantity" type="number" value={this.state.quantity} onChange={this.quantityChange} /> </li> <li> <label>Price</label> <input id="price" type="number" value={this.state.price} onChange={this.priceChange} /> </li> </ul> </div> </div> </div> ); } });
The final component to collect data and send an ajax request
EventCreation = React.createClass({ getInitialState: function(){ return {} }, submit: function (e){ var self e.preventDefault() self = this var data = {
source share