I want to add the onFocus event handler on my element only if a condition is true. Right now, I was hoping to be able to do a ternary on the onFocus itself, so something like this:
<input
type='text'
className='some-class'
value={value}
onFocus={useTheOnFocus ? evt => onFocusHandler(evt) : null}
onChange={evt => onChangeHandler(evt.target.value)}
/>
This however, does not work and generates a series of errors and warnings:
Uncaught TypeError: handler.apply is not a function
Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
I know the alternative would be to just write the input tag twice within it's own ternary one with the onFocus and the other without it. But I would like to do it in a more condensed matter. Is there another simpler and more condensed way to get this done?
nulljust use() => {}?