Event Handlers in React Stateless Components

Applying handlers to elements in function components should generally just look like this:

const f = props => <button onClick={props.onClick}></button>

If you need to do anything much more complex it’s a sign that either a) the component shouldn’t be stateless (use a class, or hooks), or b) you should be creating the handler in an outer stateful container component.

As an aside, and undermining my first point slightly, unless the component is in a particularly intensively re-rendered part of the app there’s no need to worry about creating arrow functions in render().

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)