Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  69] [ 2]  / answers: 1 / hits: 15489  / 8 Years ago, tue, december 6, 2016, 12:00:00

I am new to React js.I am little bit confused that how get id and onChange evt value at the same time when all the data inside map function.Yes there are already answers out there but nothing worked for me.Any method or help would be appreciated.
Thanks in advance.



import React from 'react'
import {connect} from 'react-redux'

class Upload extends React.Component{

constructor(props){
super(props);
this.handleChangeSinglePost = this.handleChangeSinglePost.bind(this)
this.handleID = this.handleID.bind(this)
}
handleChangeSinglePost(data){
console.log(data)//Get the input//Not working

}
handleID(e){

console.log(e.target.value)get the Id
}
renderMaptheSingleUpload(){
return(
this.props.photos.photos.map((data) => {
return(
<div key={data.id} className=WholeWrapperForSingleUpload>
<div className=imageContainerUpload>
<img src={data.blobData} />
</div>
<div className=ImageTitleForUpload>
<form onChange={this.handleID}>
<input onChange={this.handleChangeSinglePost(data.id)} name=caption type=text placeholder=Caption This />
</form>
</div>
</div>
)
})
)
}
render(){
// console.log(this.props.photos)
return(
<div className=UploaContainer>
<div className=UploadContainerContents>

{this.renderMaptheSingleUpload()}

<div className=tagsForupload>
<ul>
<li>OrdinaryLife</li>
<li>OrdinaryLife</li>
<li>OrdinaryLife</li>
<li>OrdinaryLife</li>
<li>OrdinaryLife</li>
</ul>
</div>
<div className=TagItForUpload>
<form>
<input type=text placeholder=Tag it />
<input type=submit defaultValue=Post />
</form>
<div className=suggestionSystemForTagging>
<ul>
<li>Drake</li>
<li>LetMeChoose</li>
<li>LetMeChoose</li>
<li>LetMeChoose</li>
<li>LetMeChoose</li>
<li>LetMeChoose</li>
<li>LetMeChoose</li>
<li>LetMeChoose</li>
</ul>
</div>
</div>
</div>
</div>
)
}
}

const mapStateToProps = (state) => {
return {
photos:state.photoUpload
}
};

export default connect(mapStateToProps)(Upload)

More From » reactjs

 Answers
136

I think you can use function in onChange event as :



<input onChange={e=>this.handleChangeSinglePost(e.target.value, data.id)}  />

handleChangeSinglePost(value, id){
console.log(value>>>,value);
console.log(id>>>,id);
}

[#59802] Friday, December 2, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvingcarloe

Total Points: 677
Total Questions: 109
Total Answers: 96

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
irvingcarloe questions
Wed, Mar 31, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;