I am trying to create array of buttons as shown below in the code section. I am using sandbox. I'm getting the error posted below
code:
import React from "react";
import ReactDOM from "react-dom";
import createReactClass from "create-react-class";
var arrButtons = [];
var buttonStyle = {
margin: '10px 10px 10px 0'
};
class ButtonClicks extends React.Component {
constructor(props) {
super(props);
this.onClickFunction = this.onClickFunction.bind(this);
}
onClickFunction() {
console.log("hello world from button: " + i);
};
render() {
return (
for (let i = 0; i < 10; i++) {
var button = <button
style={buttonStyle}
onClick={onClickFunction}>
p.name
</button>
arrButtons.push(button);
}
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<ButtonClicks />, rootElement);
export default ButtonClicks;
error
/src/index.js: Unexpected token (21:4)
react-nativebut the code in question isreact-dom. Might want to edit this.renderonly accepts 1 element. So, I've moved theforloop and put the buttons inside adiv.