Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onmouseover not working with React.js

Tags:

reactjs

The click event works fine, but the onmouseover event does not work.

ProfImage = React.createClass({

    getInitialState: function() {
        return { showIcons: false };
    },

    onClick: function() {

        if(this.state.showIcons == true) {
            this.setState({ showIcons: false });
        }
        else {
            this.setState({ showIcons: true });
        }
    },

    onHover: function() {
        this.setState({ showIcons: true });
    },

    render: function() {

        return (
            <div>
            <span className="major">
                <img src="/images/profile-pic.png" height="100" onClick={this.onClick} onmouseover={this.onHover} />
            </span>


            { this.state.showIcons ? <SocialIcons /> : null }
            </div>

        );
    }

});
like image 382
user1072337 Avatar asked Mar 01 '16 20:03

user1072337


People also ask

How do I use onMouseOver in react JS?

We do this by adding onMouseOver to the button element. After declaring that this element has an onMouseEnter event handler, we can choose what function we want to trigger when the cursor hovers over the element. We declare a function called changeBackground above the view part of the React Component.

How do you use onMouseOut in react?

The onMouseOver event in React occurs when the mouse pointer is moved onto an element (it can be a div, a button, an input, a textarea, etc). The event handler function will be fired and we can execute our logic there. The onMouseOut event in React occurs when the mouse pointer is moved out of an element.

What is event in react JS?

An event is an action that could be triggered as a result of the user action or system generated event. For example, a mouse click, loading of a web page, pressing a key, window resizes, and other interactions are called events.


1 Answers

You need to capitalize some of the letters.

<img src="/images/profile-pic.png" height="100" onClick={this.onClick} onMouseOver={this.onHover} />
like image 85
whatoncewaslost Avatar answered Sep 19 '22 18:09

whatoncewaslost