Expand Minimize

Don't use 'return false' in a React event handler

To stop event propagation in React you should call the 'preventDefault' method on the 'event' object rather than returning 'false'

CheckId RCT010101
TypeName BadEventHandlerReturnFalseRule
Severity Error
Type React component

To stop event propagation in React you should call the preventDefault method on the event object rather than returning false.

Bad practice

export class Link extends React.Component {
    render() {
        return (
            <a href="http://contoso.com" onClick={event => false}>Contoso</a>
        );
    }
}


Good practice
export class Link extends React.Component {
    render() {
        return (
            <a href="http://contoso.com" onClick={event => event.preventDefault()}>Contoso</a>
        );
    }
}

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.