Thursday, September 4, 2025
HomeLanguagesWhat is onBeforeInputCapture Event in ReactJS ?

What is onBeforeInputCapture Event in ReactJS ?

React onBeforeInputCapture is an event handler that gets triggered when we make any modifications to the input file, like onBeforeInput, but the difference is that onBeforeInputCapture acts in the capture phase whereas onBeforeInput acts in the bubbling phase i,e. phases of an event.

Prerequisite:

Syntax:

<input  onBeforeInputCapture={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. If you have already installed create-react-app globally. If you haven’t then install create-react-app globally by using the command npm -g create-react-app or can 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 creating an input field with the label “Enter your name:”, and we are adding a default value as “default” to it. The onBeforeInputCapture event will call onBeforeInputCaptureHandler, a function that will show a text “onBeforeInputCapture” whenever any new value is added to the input field.

App.js

Javascript




function App() {
    const onBeforeInputCaptureHandler = () => {
        console.log("onBeforeInputCapture");
    }
    return (
        <div className="App">
            <h1> Hey Geek!</h1>
            <label>Enter your name:</label>
            <input type="text"
                defaultValue="default"
                onBeforeInputCapture={onBeforeInputCaptureHandler}
            />
        </div>
    );
}
  
export default App;


Step to Run 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!
RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6746 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS