Skip to content

Commit ef2d98b

Browse files
Update part1c.md
I have added a direct quote from react documentation about the naming convention for event handlers and props. The course has mixed up the naming convention of the handlers and the props. handlers should start with "handle", e.g. handleButtonClick props should start with "on", e.g. onButtonClick the course has suggested calling a prop handleClick where as it should start with on and perhaps rather than just a plane onClick have something that indicates what is being clicked to differentiate it from html buttons onClick attribute i havent changed the usage of this as it is spread throughout the whole section and i may make a more serious mistake than just getting a naming convention wrong.
1 parent dbc1cfb commit ef2d98b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/content/1/en/part1c.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,10 @@ const App = () => {
629629
630630
Since we now have an easily reusable <i>Button</i> component, we've also implemented new functionality into our application by adding a button that can be used to decrement the counter.
631631
632-
The event handler is passed to the <i>Button</i> component through the _handleClick_ prop. The name of the prop itself is not that significant, but our naming choice wasn't completely random. React's own official [tutorial](https://react.dev/learn/tutorial-tic-tac-toe) suggests this convention.
632+
The event handler is passed to the <i>Button</i> component through the _handleClick_ prop. The name of the prop itself is not that significant, but our naming choice wasn't completely random.
633+
634+
React's own official [tutorial](https://react.dev/learn/tutorial-tic-tac-toe) suggests:
635+
"In React, it’s conventional to use onSomething names for props which represent events and handleSomething for the function definitions which handle those events."
633636
634637
### Changes in state cause rerendering
635638

0 commit comments

Comments
 (0)