I have a component and three div tag's in it. In one of the div
tag, I created onMouseOver
event and trying to change color of text onMouseOver
.
React onMouseOver
, onMouseEnter
events and style are changing dynamically in React.
import React from 'react'
function Middle() {
const styles = {
'text-align': 'center',
'padding': '30px',
}
function myName() {
styles.color = "green"
}
function noName() {
}
return (
<div className="middle">
<div id="cspace" style={styles} onMouseEnter={myName} onMouseLeave={noName}>
<h1>Hello World</h1>
</div>
</div>
)
}
export default Middle
I am expecting the color of text in div to be changed. the output I am getting is:
"Cannot add property color, object is not extensible"
onMouseOver
event? You could just add:hover
to the css class of the div and change the color that way. – Riana