React - Focus Events

0 points
Created by:

In this article, we would like to show you focus events in React.

There are two focus events:

  • onFocus
  • onBlur

Note: focus events work on all elements in the React DOM.

In the following example, we create functions that handle these events and display to the console which action was performed.

Runnable example:

// ONLINE-RUNNER:browser;

// Note: Uncomment import lines during working with JSX Compiler.
// import React from "react";
// import ReactDOM from "react-dom";

const App = () => {
  const handleOnFocus = () => {
    console.log('onFocus event was handled');
  const handleOnBlur = () => {
    console.log('onBlur event was handled');

  return (
      <input type="text"
        placeholder="Click here"

const root = document.querySelector('#root');
ReactDOM.render(<App />, root);


  1. blur event (js) - MDN Docs

  2. focus event (js) - MDN Docs

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!

ReactJS - events

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂