Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"editor.defaultFormatter": "dprint.dprint"
},
"[jsonc]": {
"editor.defaultFormatter": "dprint.dprint"
"editor.defaultFormatter": "vscode.json-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ class AutoSelectingInput extends Component {

## Further Reading

- [React DOM: APIs findDOMNode](https://react.dev/reference/react-dom/findDOMNode)
- [React DOM `findDOMNode`](https://react.dev/reference/react-dom/findDOMNode)
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ flushSync(() => {

## Further Reading

- [React DOM: APIs flushSync](https://react.dev/reference/react-dom/flushSync)
- [React DOM `flushSync`](https://react.dev/reference/react-dom/flushSync)
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ hydrateRoot(document.getElementById("app"), <Component />);

## Further Reading

- [React: react-dom/hydrate](https://18.react.dev/reference/react-dom/hydrate)
- [React: react-dom/createRoot](https://react.dev/reference/react-dom/client/hydrateRoot)
- [React DOM `hydrate`](https://18.react.dev/reference/react-dom/hydrate)
- [React DOM `createRoot`](https://react.dev/reference/react-dom/client/hydrateRoot)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function MyComponent() {

## Further Reading

- [MDN: button - notes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#notes)
- [MDN `button` notes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#notes)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function MyComponent() {

## Further Reading

- [MDN: iframe - sandbox](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attributes)
- [MDN `iframe` sandbox](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attributes)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ReactDOM.render(<div id="app" ref={doSomethingWithInst} />, document.body);

## Further Reading

- [React: react-dom/render](https://18.react.dev/reference/react-dom/render)
- [React DOM `render`](https://18.react.dev/reference/react-dom/render)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ createRoot(document.getElementById("app")).render(<Component />);

## Further Reading

- [React: react-dom/render](https://18.react.dev/reference/react-dom/render)
- [React: react-dom/createRoot](https://react.dev/reference/react-dom/client/createRoot)
- [React DOM `render`](https://18.react.dev/reference/react-dom/render)
- [React DOM `createRoot`](https://react.dev/reference/react-dom/client/createRoot)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function MyComponent() {

## Further Reading

- [MDN: iframe - sandbox](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attributes)
- [MDN: `iframe` `sandbox`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attributes)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ function StatefulForm({}) {

## Further Reading

- [React: useActionState](https://react.dev/reference/react/useActionState)
- [React `useActionState` Hook](https://react.dev/reference/react/useActionState)
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function Counter() {
const [count, setCount] = useState(0);

useEffect(() => {
const handler = () => setCount(c => c + 1);
const handler = () => setCount((c) => c + 1);
window.addEventListener("click", handler);
return () => window.removeEventListener("click", handler);
}, []);
Expand All @@ -113,7 +113,7 @@ export default function Counter() {

useEffect(() => {
const intervalId = setInterval(() => {
setCount(c => c + 1);
setCount((c) => c + 1);
}, 1000);
return () => clearInterval(intervalId);
}, []);
Expand All @@ -133,8 +133,8 @@ export default function RemoteContent() {
useEffect(() => {
let discarded = false;
fetch("https://eslint-react.xyz/content")
.then(resp => resp.text())
.then(text => {
.then((resp) => resp.text())
.then((text) => {
if (discarded) return;
setContent(text);
});
Expand Down Expand Up @@ -207,7 +207,10 @@ import { useMemo, useState } from "react";
function TodoList({ todos, filter }) {
const [newTodo, setNewTodo] = useState("");
// ✅ Does not re-run getFilteredTodos() unless todos or filter change
const visibleTodos = useMemo(() => getFilteredTodos(todos, filter), [todos, filter]);
const visibleTodos = useMemo(
() => getFilteredTodos(todos, filter),
[todos, filter],
);
// ...
}
```
Expand All @@ -234,12 +237,7 @@ export default function ProfilePage({ userId }) {
import { useState } from "react";

export default function ProfilePage({ userId }) {
return (
<Profile
userId={userId}
key={userId}
/>
);
return <Profile userId={userId} key={userId} />;
}

function Profile({ userId }) {
Expand Down Expand Up @@ -292,7 +290,7 @@ function List({ items }) {
const [isReverse, setIsReverse] = useState(false);
const [selectedId, setSelectedId] = useState(null);
// ✅ Best: Calculate everything during rendering
const selection = items.find(item => item.id === selectedId) ?? null;
const selection = items.find((item) => item.id === selectedId) ?? null;
// ...
}
```
Expand All @@ -304,9 +302,9 @@ function List({ items }) {

## Further Reading

- [React: useState](https://react.dev/reference/react/useState#setstate)
- [React: useEffect](https://react.dev/reference/react/useEffect)
- [React: You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)
- [React `useState` Hook](https://react.dev/reference/react/useState)
- [React `useEffect` Hook](https://react.dev/reference/react/useEffect)
- [React Docs: You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function Counter() {
const [count, setCount] = useState(0);

useLayoutEffect(() => {
const handler = () => setCount(c => c + 1);
const handler = () => setCount((c) => c + 1);
window.addEventListener("click", handler);
return () => window.removeEventListener("click", handler);
}, []);
Expand All @@ -113,7 +113,7 @@ export default function Counter() {

useLayoutEffect(() => {
const intervalId = setInterval(() => {
setCount(c => c + 1);
setCount((c) => c + 1);
}, 1000);
return () => clearInterval(intervalId);
}, []);
Expand All @@ -133,8 +133,8 @@ export default function RemoteContent() {
useLayoutEffect(() => {
let discarded = false;
fetch("https://eslint-react.xyz/content")
.then(resp => resp.text())
.then(text => {
.then((resp) => resp.text())
.then((text) => {
if (discarded) return;
setContent(text);
});
Expand Down Expand Up @@ -207,7 +207,10 @@ import { useMemo, useState } from "react";
function TodoList({ todos, filter }) {
const [newTodo, setNewTodo] = useState("");
// ✅ Does not re-run getFilteredTodos() unless todos or filter change
const visibleTodos = useMemo(() => getFilteredTodos(todos, filter), [todos, filter]);
const visibleTodos = useMemo(
() => getFilteredTodos(todos, filter),
[todos, filter],
);
// ...
}
```
Expand All @@ -234,12 +237,7 @@ export default function ProfilePage({ userId }) {
import { useState } from "react";

export default function ProfilePage({ userId }) {
return (
<Profile
userId={userId}
key={userId}
/>
);
return <Profile userId={userId} key={userId} />;
}

function Profile({ userId }) {
Expand Down Expand Up @@ -292,7 +290,7 @@ function List({ items }) {
const [isReverse, setIsReverse] = useState(false);
const [selectedId, setSelectedId] = useState(null);
// ✅ Best: Calculate everything during rendering
const selection = items.find(item => item.id === selectedId) ?? null;
const selection = items.find((item) => item.id === selectedId) ?? null;
// ...
}
```
Expand All @@ -304,9 +302,9 @@ function List({ items }) {

## Further Reading

- [React: useState](https://react.dev/reference/react/useState#setstate)
- [React: useLayoutEffect](https://react.dev/reference/react/useLayoutEffect)
- [React: You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)
- [React `useState` Hook](https://react.dev/reference/react/useState)
- [React `useLayoutEffect` Hook](https://react.dev/reference/react/useLayoutEffect)
- [React Docs: You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@ function useAuth() {

## Further Reading

- [React: invalid-hook-call-warning (the first note)](https://react.dev/warnings/invalid-hook-call-warning)
- [React: should-all-functions-called-during-rendering-start-with-the-use-prefix (the deep dive)](https://react.dev/learn/reusing-logic-with-custom-hooks#should-all-functions-called-during-rendering-start-with-the-use-prefix)
- [React Docs: Should all functions called during rendering start with the `use` prefix? (the deep dive)](https://react.dev/learn/reusing-logic-with-custom-hooks#should-all-functions-called-during-rendering-start-with-the-use-prefix)
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ declare function generateTodos(): string[];

## Further Reading

- [React: useState](https://react.dev/reference/react/useState#setstate)
- [React `useState` Hook](https://react.dev/reference/react/useState#setstate)
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ import { useEffect } from "react";

function MyComponent() {
useEffect(() => {
const events = ["mousemove", "mousedown", "keydown", "scroll", "touchstart"];
const events = [
"mousemove",
"mousedown",
"keydown",
"scroll",
"touchstart",
];
const handleActivity = () => {};

events.forEach((event) => {
Expand Down Expand Up @@ -254,7 +260,7 @@ function useCustomHook() {

## Further Reading

- [MDN: EventTarget.addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
- [MDN: EventTarget.removeEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener)
- [React: Subscribing to events](https://react.dev/learn/synchronizing-with-effects#subscribing-to-events)
- [React: Connecting to an external system](https://react.dev/reference/react/useEffect#connecting-to-an-external-system)
- [MDN: `EventTarget.addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener)
- [MDN: `EventTarget.removeEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener)
- [React Docs: Subscribing to events](https://react.dev/learn/synchronizing-with-effects#subscribing-to-events)
- [React Docs: Connecting to an external system](https://react.dev/reference/react/useEffect#connecting-to-an-external-system)
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function MyComponent() {

## Further Reading

- [MDN: setInterval](https://developer.mozilla.org/en-US/docs/Web/API/setInterval)
- [MDN: clearInterval](https://developer.mozilla.org/en-US/docs/Web/API/clearInterval)
- [React: synchronizing with effects](https://react.dev/learn/synchronizing-with-effects#putting-it-all-together)
- [MDN: `setInterval`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval)
- [MDN: `clearInterval`](https://developer.mozilla.org/en-US/docs/Web/API/clearInterval)
- [React Docs: Synchronizing with effects](https://react.dev/learn/synchronizing-with-effects#putting-it-all-together)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ function MyComponent() {

## Further Reading

- [MDN: ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
- [React: Connecting to an external system](https://react.dev/reference/react/useEffect#connecting-to-an-external-system)
- [MDN: `ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
- [React Docs: Connecting to an external system](https://react.dev/reference/react/useEffect#connecting-to-an-external-system)
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ function MyComponent() {

## Further Reading

- [MDN: setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout)
- [MDN: clearTimeout](https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout)
- [React: synchronizing with effects](https://react.dev/learn/synchronizing-with-effects#putting-it-all-together)
- [MDN: `setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout)
- [MDN: `clearTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout)
- [React Docs: Synchronizing with effects](https://react.dev/learn/synchronizing-with-effects#putting-it-all-together)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function MyComponent({ items }: MyComponentProps) {

## Further Reading

- [React: Why does React need keys?](https://react.dev/learn/rendering-lists#why-does-react-need-keys)
- [React Docs: Why does React need keys?](https://react.dev/learn/rendering-lists#why-does-react-need-keys)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function MyComponent({ children }: MyComponentProps) {

## Further Reading

- [React: Legacy React APIs Children](https://react.dev/reference/react/Children)
- [Legacy React APIs `Children`](https://react.dev/reference/react/Children)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function MyComponent({ children }: MyComponentProps) {

## Further Reading

- [React: Legacy React APIs Children](https://react.dev/reference/react/Children)
- [Legacy React APIs `Children`](https://react.dev/reference/react/Children)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function MyComponent({ children }: MyComponentProps) {

## Further Reading

- [React: Legacy React APIs Children](https://react.dev/reference/react/Children)
- [Legacy React APIs `Children`](https://react.dev/reference/react/Children)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function MyComponent({ children }: MyComponentProps) {

## Further Reading

- [React: Legacy React APIs Children](https://react.dev/reference/react/Children)
- [Legacy React APIs `Children`](https://react.dev/reference/react/Children)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function MyComponent({ children }: MyComponentProps) {

## Further Reading

- [React: Legacy React APIs Children](https://react.dev/reference/react/Children)
- [Legacy React APIs `Children`](https://react.dev/reference/react/Children)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ class ErrorBoundary extends Component<ErrorBoundaryProps> {

## Further Reading

- [React: Legacy React APIs Component](https://react.dev/reference/react/Component)
- [Legacy React APIs `Component`](https://react.dev/reference/react/Component)
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ console.log(clonedElement); // <Row title="Cabbage" isHighlighted={true}>Goodbye

## Further Reading

- [React: Legacy React APIs cloneElement](https://react.dev/reference/react/cloneElement)
- [Legacy React APIs `cloneElement`](https://react.dev/reference/react/cloneElement)
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MyComponent extends React.Component<MyComponentProps> {

## Further Reading

- [React: Legacy React APIs componentWillMount](https://react.dev/reference/react/Component#componentwillmount)
- [Legacy React APIs `componentWillMount`](https://react.dev/reference/react/Component#componentwillmount)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MyComponent extends React.Component {

## Further Reading

- [React: Legacy React APIs componentWillReceiveProps](https://react.dev/reference/react/Component#componentwillreceiveprops)
- [Legacy React APIs `componentWillReceiveProps`](https://react.dev/reference/react/Component#componentwillreceiveprops)

---

Expand Down
Loading
Loading