Created
February 22, 2021 17:08
7. Undefined props - Bad Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
const ButtonOne = ({ handleClick }) => ( | |
<button onClick={handleClick || undefined}>Click me</button> | |
) | |
const ButtonTwo = ({ handleClick }) => { | |
const noop = () => {} | |
return <button onClick={handleClick || noop}>Click me</button> | |
} | |
export const UndefinedPropsBad = () => ( | |
<div> | |
<ButtonOne /> | |
<ButtonOne handleClick={() => alert('Clicked!')} /> | |
<ButtonTwo /> | |
<ButtonTwo handleClick={() => alert('Clicked!')} /> | |
</div> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment