All Articles

How I name event handlers in React with TypeScript.

⁉️ Why?

Predictable naming conventions can provide a better code style and boost your code reusability.

💻 How?

  • I use the on prefix for handlers in props. ` onAddButtonClick `, ` onModalClose `.
  • I use the handle prefix for function handlers. ` handleAddButtonClick `, ` handleModalClose `.

📌 Example!

<AddButton onAddButtonClick={handleAddButtonClick}>ADD</button>

<Modal onModalClose={handleModalClose}>Modal</Modal>