diff --git a/docs/style.md b/docs/style.md index e62f0bcdc396..5e0491648cd7 100644 --- a/docs/style.md +++ b/docs/style.md @@ -207,3 +207,65 @@ MyComponent.propTypes = { _Note: not every component will mirror the structure above. Some will need to incorporate `useEffect`, some will not. You can think of the outline above as slots that you can fill if you need this functionality in a component._ + +### Style + +#### Naming event handlers + +
Unpreferred | Preferred |
---|---|
+ +```jsx +function MyComponent() { + function click() { + // ... + } + return ; +} +``` + + | + +```jsx +function MyComponent() { + function onClick() { + // ... + } + return ; +} +``` + + |
+ +```jsx +function MyComponent({ onClick }) { + function handleClick(event) { + // ... + onClick(event); + } + return ; +} +``` + + | + +```jsx +function MyComponent({ onClick }) { + function handleOnClick(event) { + // ... + onClick(event); + } + return ; +} +``` + + |