Answer the question
In order to leave comments, you need to log in
How to pass value from list to React?
The code is very simple, I think it's too much to describe here
class App extends React.Component{
state = {
titel: 'List',
arr: [
'simon', 'dima', 'kosty'
]
}
ren(){
alert( --- здесь должно быть значение текущего варианта списка --- )
}
render(){
return(
<div>
<h1>{this.state.titel}</h1>
<ol>
{this.state.arr.map(
(list, key) =>
<li onClick={this.ren.bind(this)}>{list}</li>
)}
</ol>
</div>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
Answer the question
In order to leave comments, you need to log in
class App extends React.Component{
state = {
title: 'List',
arr: [
'simon','dima','kosty'
]
}
ren = ({target}) => {
alert(target.textContent);
}
render(){
return(
<div>
<h1>{this.state.title}</h1>
<ol>
{this.state.arr.map(
(list, key) =>
<li onClick={this.ren} key={key}>{list}</li>
)}
</ol>
</div>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question