Thursday, January 9, 2025
Google search engine
HomeLanguagesWhat is onMouseOutCapture in ReactJS ?

What is onMouseOutCapture in ReactJS ?

React onMouseOutCapture is an event handler that gets triggered whenever the pointer of the mouse is moved out of an element or its children. like onMouseOut, but the difference is that onMouseOutCapture acts in the capture phase whereas onMouseOut acts in the bubbling phase i.e. phases of an event.

Prerequisite:

Syntax:

<element onMouseOutCapture={function}/>

Creating React Application:

Step 1: Create a react project folder, for that open the terminal, and write the command npm create-react-app folder name. Suppose you have already installed create-react-app globally. If you haven’t, install create-react-app globally using the command npm -g create-react-app or install locally by npm i create-react-app.

npm create-react-app project

Step 2: After creating your project folder(i.e. project), move to it by using the following command.

cd project

Project Structure: It will look like this:

 

Example: In this example, we are adding a text within the <p> tag i.e. ” Mouse over this line and leave!”. The onMouseOutCapture event will call onMouseOutCaptureHandler, a function that will show a text “onMouseOutCapture Event!” whenever we move the pointer of the mouse out of the element, in the console.

App.js




function App() {
  const onMouseOutCaptureHandler = () => {
    console.log("onMouseOutCapture Event!");
  };
  return (
    <div className="App">
      <h1> Hey Geek!</h1>
      <p onMouseOutCapture={onMouseOutCaptureHandler}>
        Mouse over this line and leave!
      </p>
  
    </div>
  );
}
  
export default App;


Step to Run the Application: Run the application using the following command from the root directory of the project.

npm start

Output:

 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Previous article
Next article
RELATED ARTICLES

Most Popular

Recent Comments