VOOZH about

URL: https://www.geeksforgeeks.org/reactjs/react-onmousemove-event/

⇱ React onMouseMove Event - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

React onMouseMove Event

Last Updated : 23 Jul, 2025

React onMouseMove event detects a mouse movement over an element. The event triggers when the mouse pointer moves while positioned over an element. It is particularly useful where you want to track and respond to the movement of the user's cursor.

It is similar to the HTML DOM onmousemove event but uses the camelCase convention in React.

Syntax:

<element onMouseMove={function}/>

Parameter: The parameter for the onMouseEnter event handler is a function that contains the action to be taken when the mouse moves within the element.

Return type: The return type of the function attached to onMouseEnter is usually void because it doesn't explicitly return anything, but it can perform actions, update state, or trigger other functions as needed within the component.

Example 1 : This example demonstrates the use of the onMouseMove event handler.

Output:

👁 Animation4

Example 2 : This example demonstrates the canvas drawing with the help of onMouseMove event handler.

Output:

👁 Animation6

Comment
Article Tags: