Skip to content

Commit

Permalink
Use console.log in tutorial instead of alert (#3831)
Browse files Browse the repository at this point in the history
* Updating tutorial to use console.log instead of alert

Chrome is deprecating alerts

* Revert remove space from my auto-linter

Co-authored-by: Bev Lau <[email protected]>
  • Loading branch information
bev-a-tron and Bev Lau authored Aug 4, 2021
1 parent 9c2b800 commit 669890b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions content/tutorial/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ First, change the button tag that is returned from the Square component's `rende
class Square extends React.Component {
render() {
return (
<button className="square" onClick={function() { alert('click'); }}>
<button className="square" onClick={function() { console.log('click'); }}>
{this.props.value}
</button>
);
}
}
```

If you click on a Square now, you should see an alert in your browser.
If you click on a Square now, you should see 'click' in your browser's devtools console.

>Note
>
Expand All @@ -253,15 +253,15 @@ If you click on a Square now, you should see an alert in your browser.
>class Square extends React.Component {
> render() {
> return (
> <button className="square" onClick={() => alert('click')}>
> <button className="square" onClick={() => console.log('click')}>
> {this.props.value}
> </button>
> );
> }
>}
>```
>
>Notice how with `onClick={() => alert('click')}`, we're passing *a function* as the `onClick` prop. React will only call this function after a click. Forgetting `() =>` and writing `onClick={alert('click')}` is a common mistake, and would fire the alert every time the component re-renders.
>Notice how with `onClick={() => console.log('click')}`, we're passing *a function* as the `onClick` prop. React will only call this function after a click. Forgetting `() =>` and writing `onClick={console.log('click')}` is a common mistake, and would fire every time the component re-renders.
As a next step, we want the Square component to "remember" that it got clicked, and fill it with an "X" mark. To "remember" things, components use **state**.
Expand All @@ -280,7 +280,7 @@ class Square extends React.Component {
render() {
return (
<button className="square" onClick={() => alert('click')}>
<button className="square" onClick={() => console.log('click')}>
{this.props.value}
</button>
);
Expand Down

0 comments on commit 669890b

Please sign in to comment.