I'm trying to make a variable called Characters to render three different buttons when it is clicked, for now, I've tried putting the three HTML elements in the same variable but it is not working as I think that's not the correct way to do it.
I've tried this:
if (!hidden) {
Characters = <button>Star</button>
<button>Toad</button>
<button>x</button>
}
But it is not working.
import React, {useState} from 'react'
import mainImage from '../img/marioBrosMain.jpg'
import '../main.css'
import Box from '../pages/box.js'
function Main() {
const [style, setStyle] = useState();
const [hidden, setHidden] = useState(true)
let Characters;
const imageClick = (x, y) => {
const newStyle = {
position: "absolute",
zIndex: 2,
borderRadius: "2px solid red",
border: "4px solid red",
height: "50px",
paddingLeft: "50px",
left: `${x}px`,
top: `${y}px`
}
setHidden(false)
return newStyle
}
if (!hidden) {
Characters = <button>Star</button>
}
return (
<div id="frame">
<div id="mainImage" style = {style}>
{Characters}
</div>
<img src={mainImage} className="marioBros____image" onClick={e => setStyle(imageClick(e.pageX, e.pageY))} />
</div>
)
}
export default Main