In my React app I am having arrays in my variable, and they are rendered as a single element. For example r: ['reply1-1', 'reply1-2'] is rendered as a reply1-1reply1-2, together. I dont know how to <br/> them, or to make separate buttons.
Code:
class App extends Component {
constructor() {
super();
this.state = { currentDialog: 0 }
}
render() {
var dialogs = [
{
id: uuid.v4(),
q: 'dialog1',
r: ['reply1-1', 'reply1-2']
},
{
id: uuid.v4(),
q: 'dialog2',
r: ['reply2-1', 'reply2-2']
},
{
id: uuid.v4(),
q: 'dialog3',
r: ['reply3-1', 'reply3-2']
},
{
id: uuid.v4(),
q: 'dialog4',
r: ['reply4-1', 'reply4-2']
}
]
var replyList = dialogs.map(reply => {
return (
<div>
{reply.r}
</div>
);
});
return(
<div className="App">
{dialogs[this.state.currentDialog].q}
<br /><br />
{replyList[this.state.currentDialog]}
<br /><br />
<button onClick={() => {
this.currentDialogMinus()
}}>PREV</button>
<button onClick={() => {
this.currentDialogPlus()
}}>NEXT</button>
</div>)
}
currentDialogPlus() {
this.setState(
{
currentDialog: this.state.currentDialog + 1
}
);
}
currentDialogMinus() {
this.setState(
{
currentDialog: this.state.currentDialog - 1
}
);
}
}
export default App;