DEV Community

Discussion on: React Cheat sheet (Updated June 2021)

Collapse
 
xardonik profile image
XardoniK • Edited

I found small mistake in "e for event arguments":

This won't work because you pass string as an argument

const clickHandler = (e) => console.log(e.target)
function App(){
    return (
        <>
            <h1>Welcome to my app</h1>
            <button onClick={() => clickHandler(*'Hello World'*)}>Say Hi</button>
        </> 
    )
} 
Enter fullscreen mode Exit fullscreen mode

There are two ways how to do it:
1.

const clickHandler = (e) => console.log(e.target)
function App(){
    return (
        <>
            <h1>Welcome to my app</h1>
            <button onClick={(e) => clickHandler(e)}>Say Hi</button>
        </> 
    )
} 
Enter fullscreen mode Exit fullscreen mode

2.

const clickHandler = (e) => console.log(e.target)
function App(){
    return (
        <>
            <h1>Welcome to my app</h1>
            <button onClick={clickHandler}>Say Hi</button>
        </> 
    )
} 
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ericchapman profile image
Eric The Coder

Ok thanks I made the correction

Collapse
 
linusvallejo profile image
LinusVallejo

Exactly

Collapse
 
elibates profile image
Eli Bates

Thanks! Will use

Collapse
 
ccrystle profile image
Charlie

thanks--helpful post.

there's a typo: import {Greeting} from './Gretting'