Skip to content

Commit 673ea06

Browse files
committed
chore: format all files
1 parent 634e5af commit 673ea06

File tree

46 files changed

+142
-201
lines changed
  • questions
    • explain-one-way-data-flow-of-react-and-its-benefits
    • explain-server-side-rendering-of-react-applications-and-its-benefits
    • explain-static-generation-of-react-applications-and-its-benefits
    • explain-the-composition-pattern-in-react
    • explain-the-presentational-vs-container-component-pattern-in-react
    • explain-what-happens-when-setstate-is-called-in-react
    • explain-what-react-hydration-is
    • how-do-you-debug-react-applications
    • how-do-you-decide-between-using-react-state-context-and-external-state-managers
    • how-do-you-handle-asynchronous-data-loading-in-react-applications
    • how-do-you-localize-react-applications
    • how-do-you-reset-a-components-state-in-react
    • how-do-you-test-react-applications
    • how-does-virtual-dom-in-react-work-what-are-its-benefits-and-downsides
    • what-are-error-boundaries-in-react-for
    • what-are-higher-order-components-in-react
    • what-are-react-fragments-used-for
    • what-are-react-portals-used-for
    • what-are-render-props-in-react-and-what-are-they-for
    • what-are-some-common-pitfalls-when-doing-data-fetching-in-react
    • what-are-some-pitfalls-about-using-context-in-react
    • what-are-some-react-anti-patterns
    • what-are-the-benefits-of-using-hooks-in-react
    • what-are-the-rules-of-react-hooks
    • what-does-re-rendering-mean-in-react
    • what-does-the-dependency-array-of-useeffect-affect
    • what-is-code-splitting-in-a-react-application
    • what-is-forwardref-in-react-used-for
    • what-is-jsx-and-how-does-it-work
    • what-is-react-fiber-and-how-is-it-an-improvement-over-the-previous-approach
    • what-is-react-strict-mode-and-what-are-its-benefits
    • what-is-react-suspense-and-what-does-it-enable
    • what-is-reconciliation-in-react
    • what-is-the-consequence-of-using-array-indices-as-the-value-for-key-s-in-react
    • what-is-the-difference-between-controlled-and-uncontrolled-react-components
    • what-is-the-difference-between-react-node-react-element-and-a-react-component
    • what-is-the-difference-between-state-and-props-in-react
    • what-is-the-purpose-of-callback-function-argument-format-of-setstate-in-react-and-when-should-it-be-used
    • what-is-the-purpose-of-the-key-prop-in-react
    • what-is-the-usecallback-hook-in-react-and-when-should-it-be-used
    • what-is-the-useid-hook-in-react-and-when-should-it-be-used
    • what-is-the-usememo-hook-in-react-and-when-should-it-be-used
    • what-is-the-usereducer-hook-in-react-and-when-should-it-be-used
    • what-is-the-useref-hook-in-react-and-when-should-it-be-used
    • what-is-virtual-dom-in-react
    • why-does-react-recommend-against-mutating-state

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+142
-201
lines changed

questions/explain-one-way-data-flow-of-react-and-its-benefits/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,3 @@ One-way data flow can lead to better performance because it reduces the complexi
7676
- [React documentation on components and props](https://reactjs.org/docs/components-and-props.html)
7777
- [React documentation on state and lifecycle](https://reactjs.org/docs/state-and-lifecycle.html)
7878
- [React documentation on lifting state up](https://reactjs.org/docs/lifting-state-up.html)
79-

questions/explain-server-side-rendering-of-react-applications-and-its-benefits/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,3 @@ export default Home;
6767
- [Next.js Documentation](https://nextjs.org/docs)
6868
- [React Server Components](https://reactjs.org/docs/react-server.html)
6969
- [Server-side rendering in React](https://reactjs.org/docs/react-dom-server.html)
70-

questions/explain-static-generation-of-react-applications-and-its-benefits/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,3 @@ In this example, the `getStaticProps` function fetches data at build time, and t
7979
- [Next.js documentation on static generation](https://nextjs.org/docs/basic-features/pages#static-generation-recommended)
8080
- [React official documentation](https://reactjs.org/docs/getting-started.html)
8181
- [Static site generators comparison](https://www.staticgen.com/)
82-

questions/explain-the-composition-pattern-in-react/en-US.mdx

+5-23
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ function WelcomeDialog() {
1717
}
1818

1919
function Dialog(props) {
20-
return (
21-
<div className="dialog">
22-
{props.children}
23-
</div>
24-
);
20+
return <div className="dialog">{props.children}</div>;
2521
}
2622
```
2723

@@ -41,11 +37,7 @@ One common way to use composition is by passing components as children to other
4137

4238
```jsx
4339
function Dialog(props) {
44-
return (
45-
<div className="dialog">
46-
{props.children}
47-
</div>
48-
);
40+
return <div className="dialog">{props.children}</div>;
4941
}
5042

5143
function WelcomeDialog() {
@@ -66,23 +58,14 @@ Another way to achieve composition is by passing components as props. This allow
6658
function SplitPane(props) {
6759
return (
6860
<div className="split-pane">
69-
<div className="split-pane-left">
70-
{props.left}
71-
</div>
72-
<div className="split-pane-right">
73-
{props.right}
74-
</div>
61+
<div className="split-pane-left">{props.left}</div>
62+
<div className="split-pane-right">{props.right}</div>
7563
</div>
7664
);
7765
}
7866

7967
function App() {
80-
return (
81-
<SplitPane
82-
left={<Contacts />}
83-
right={<Chat />}
84-
/>
85-
);
68+
return <SplitPane left={<Contacts />} right={<Chat />} />;
8669
}
8770
```
8871

@@ -102,4 +85,3 @@ function App() {
10285
- [React documentation on composition vs inheritance](https://reactjs.org/docs/composition-vs-inheritance.html)
10386
- [React patterns: Composition](https://reactpatterns.com/#composition)
10487
- [Medium article on React composition](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)
105-

questions/explain-the-presentational-vs-container-component-pattern-in-react/en-US.mdx

+2-10
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ Presentational components are primarily concerned with the UI. They receive data
2626

2727
```jsx
2828
const Button = ({ onClick, label }) => (
29-
<button onClick={onClick}>
30-
{label}
31-
</button>
29+
<button onClick={onClick}>{label}</button>
3230
);
3331
```
3432

@@ -62,12 +60,7 @@ class ButtonContainer extends Component {
6260
};
6361

6462
render() {
65-
return (
66-
<Button
67-
onClick={this.handleClick}
68-
label="Click me"
69-
/>
70-
);
63+
return <Button onClick={this.handleClick} label="Click me" />;
7164
}
7265
}
7366

@@ -89,4 +82,3 @@ export default connect(null, mapDispatchToProps)(ButtonContainer);
8982
- [React documentation on components and props](https://reactjs.org/docs/components-and-props.html)
9083
- [Dan Abramov's article on presentational and container components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0)
9184
- [Redux documentation on presentational and container components](https://redux.js.org/basics/usage-with-react#presentational-and-container-components)
92-

questions/explain-what-happens-when-setstate-is-called-in-react/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@ this.setState({ count: this.state.count + 1 }, () => {
5656
- [React documentation on setState](https://reactjs.org/docs/react-component.html#setstate)
5757
- [Understanding setState in React](https://medium.com/@baphemot/understanding-react-setstate-a4640451865b)
5858
- [React's setState explained](https://daveceddia.com/where-fetch-data-componentwillmount-vs-componentdidmount/)
59-

questions/explain-what-react-hydration-is/en-US.mdx

+16-19
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,28 @@ Here's a simple example to illustrate the concept:
2828

2929
1. **Server-side rendering**: The server generates the following HTML:
3030

31-
```html
32-
<div id="root">
33-
<button>Click me</button>
34-
</div>
35-
```
31+
```html
32+
<div id="root">
33+
<button>Click me</button>
34+
</div>
35+
```
3636

3737
2. **Client-side hydration**: When the HTML is sent to the client, React hydrates it with the following code:
3838

39-
```jsx
40-
import React from 'react';
41-
import ReactDOM from 'react-dom';
39+
```jsx
40+
import React from 'react';
41+
import ReactDOM from 'react-dom';
4242

43-
function App() {
44-
const handleClick = () => {
45-
alert('Button clicked!');
46-
};
43+
function App() {
44+
const handleClick = () => {
45+
alert('Button clicked!');
46+
};
4747

48-
return (
49-
<button onClick={handleClick}>Click me</button>
50-
);
51-
}
48+
return <button onClick={handleClick}>Click me</button>;
49+
}
5250

53-
ReactDOM.hydrate(<App />, document.getElementById('root'));
54-
```
51+
ReactDOM.hydrate(<App />, document.getElementById('root'));
52+
```
5553

5654
In this example, the server sends the static HTML with a button to the client. React then hydrates the button by attaching the `onClick` event listener, making it interactive.
5755

@@ -71,4 +69,3 @@ In this example, the server sends the static HTML with a button to the client. R
7169
- [React documentation on hydration](https://reactjs.org/docs/react-dom.html#hydrate)
7270
- [Server-side rendering in React](https://reactjs.org/docs/react-dom-server.html)
7371
- [Next.js documentation on hydration](https://nextjs.org/docs/basic-features/pages#hydration)
74-

questions/how-do-you-debug-react-applications/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,3 @@ function MyComponent() {
9797
- [Error boundaries in React](https://reactjs.org/docs/error-boundaries.html)
9898
- [Using the Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools)
9999
- [Debugging JavaScript](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging)
100-

questions/how-do-you-decide-between-using-react-state-context-and-external-state-managers/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,3 @@ function App() {
162162
- [React documentation on context](https://reactjs.org/docs/context.html)
163163
- [Redux documentation](https://redux.js.org/)
164164
- [MobX documentation](https://mobx.js.org/README.html)
165-

questions/how-do-you-handle-asynchronous-data-loading-in-react-applications/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,3 @@ function DataFetchingComponent() {
160160
- [Using the Effect Hook](https://reactjs.org/docs/hooks-effect.html)
161161
- [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
162162
- [Handling errors in async functions](https://javascript.info/async-await#error-handling)
163-

questions/how-do-you-localize-react-applications/en-US.mdx

+12-15
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,17 @@ import { initReactI18next } from 'react-i18next';
6161
import en from './locales/en.json';
6262
import fr from './locales/fr.json';
6363

64-
i18n
65-
.use(initReactI18next)
66-
.init({
67-
resources: {
68-
en: { translation: en },
69-
fr: { translation: fr },
70-
},
71-
lng: 'en', // default language
72-
fallbackLng: 'en',
73-
interpolation: {
74-
escapeValue: false, // react already safes from xss
75-
},
76-
});
64+
i18n.use(initReactI18next).init({
65+
resources: {
66+
en: { translation: en },
67+
fr: { translation: fr },
68+
},
69+
lng: 'en', // default language
70+
fallbackLng: 'en',
71+
interpolation: {
72+
escapeValue: false, // react already safes from xss
73+
},
74+
});
7775

7876
export default i18n;
7977
```
@@ -94,7 +92,7 @@ ReactDOM.render(
9492
<I18nextProvider i18n={i18n}>
9593
<App />
9694
</I18nextProvider>,
97-
document.getElementById('root')
95+
document.getElementById('root'),
9896
);
9997
```
10098

@@ -147,4 +145,3 @@ export default LanguageSwitcher;
147145
- [react-i18next documentation](https://react.i18next.com/)
148146
- [i18next documentation](https://www.i18next.com/)
149147
- [react-intl documentation](https://formatjs.io/docs/react-intl/)
150-

questions/how-do-you-reset-a-components-state-in-react/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,3 @@ export default MyComponent;
117117
- [React useState Hook](https://reactjs.org/docs/hooks-state.html)
118118
- [React Component State](https://reactjs.org/docs/state-and-lifecycle.html)
119119
- [React Functional Components](https://reactjs.org/docs/components-and-props.html#function-and-class-components)
120-

questions/how-do-you-test-react-applications/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,3 @@ test('matches the snapshot', () => {
8888
- [React Testing Library documentation](https://testing-library.com/docs/react-testing-library/intro)
8989
- [Cypress documentation](https://docs.cypress.io/guides/overview/why-cypress)
9090
- [Snapshot testing with Jest](https://jestjs.io/docs/snapshot-testing)
91-

questions/how-does-virtual-dom-in-react-work-what-are-its-benefits-and-downsides/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,3 @@ In this example, when the button is clicked, the state changes, triggering a new
7878
- [React documentation on reconciliation](https://reactjs.org/docs/reconciliation.html)
7979
- [Understanding the virtual DOM](https://medium.com/@deathmood/how-to-write-your-own-virtual-dom-ee74acc13060)
8080
- [React performance optimization](https://reactjs.org/docs/optimizing-performance.html)
81-

questions/what-are-error-boundaries-in-react-for/en-US.mdx

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ErrorBoundary extends Component {
3939

4040
componentDidCatch(error, errorInfo) {
4141
// You can also log the error to an error reporting service
42-
console.error("Error caught by ErrorBoundary: ", error, errorInfo);
42+
console.error('Error caught by ErrorBoundary: ', error, errorInfo);
4343
}
4444

4545
render() {
@@ -48,7 +48,7 @@ class ErrorBoundary extends Component {
4848
return <h1>Something went wrong.</h1>;
4949
}
5050

51-
return this.props.children;
51+
return this.props.children;
5252
}
5353
}
5454

@@ -85,4 +85,3 @@ Error boundaries have some limitations:
8585
- [React documentation on error boundaries](https://reactjs.org/docs/error-boundaries.html)
8686
- [Handling errors in React](https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html)
8787
- [Error boundaries in React 16](https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html)
88-

questions/what-are-higher-order-components-in-react/en-US.mdx

-1
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,3 @@ In this example, `withExtraProps` is an HOC that adds an `extraProp` to `MyCompo
8585
- [React documentation on higher order components](https://reactjs.org/docs/higher-order-components.html)
8686
- [Understanding higher order components in React](https://medium.com/@franleplant/react-higher-order-components-in-depth-cf9032ee6c3e)
8787
- [HOCs vs Render Props vs Hooks](https://blog.logrocket.com/hooks-vs-render-props-vs-hocs/)
88-

questions/what-are-react-fragments-used-for/en-US.mdx

+17-18
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@ There are two ways to use React Fragments:
3333

3434
1. **Shorthand syntax**: This is the most concise way to use fragments. It uses empty tags `<>...</>`.
3535

36-
```jsx
37-
return (
38-
<>
39-
<ChildComponent1 />
40-
<ChildComponent2 />
41-
</>
42-
);
43-
```
36+
```jsx
37+
return (
38+
<>
39+
<ChildComponent1 />
40+
<ChildComponent2 />
41+
</>
42+
);
43+
```
4444

4545
2. **Full syntax**: This uses `React.Fragment` and can be useful if you need to add keys to the fragment.
4646

47-
```jsx
48-
return (
49-
<React.Fragment>
50-
<ChildComponent1 />
51-
<ChildComponent2 />
52-
</React.Fragment>
53-
);
54-
```
47+
```jsx
48+
return (
49+
<React.Fragment>
50+
<ChildComponent1 />
51+
<ChildComponent2 />
52+
</React.Fragment>
53+
);
54+
```
5555

5656
### Adding keys to fragments
5757

@@ -60,7 +60,7 @@ If you need to add keys to the elements within a fragment, you must use the full
6060
```jsx
6161
return (
6262
<React.Fragment>
63-
{items.map(item => (
63+
{items.map((item) => (
6464
<ChildComponent key={item.id} />
6565
))}
6666
</React.Fragment>
@@ -78,4 +78,3 @@ return (
7878
- [React Fragments - Official Documentation](https://reactjs.org/docs/fragments.html)
7979
- [React Fragments - A Complete Guide](https://www.freecodecamp.org/news/react-fragments-complete-guide/)
8080
- [When to use React Fragments](https://blog.logrocket.com/when-to-use-react-fragments/)
81-

questions/what-are-react-portals-used-for/en-US.mdx

+5-10
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ const Modal = ({ isOpen, children }) => {
2828
if (!isOpen) return null;
2929

3030
return ReactDOM.createPortal(
31-
<div className="modal">
32-
{children}
33-
</div>,
34-
document.getElementById('modal-root')
31+
<div className="modal">{children}</div>,
32+
document.getElementById('modal-root'),
3533
);
3634
};
3735
```
@@ -55,7 +53,7 @@ const Tooltip = ({ text, targetRef }) => {
5553
<div className="tooltip" style={tooltipStyle}>
5654
{text}
5755
</div>,
58-
document.body
56+
document.body,
5957
);
6058
};
6159
```
@@ -72,10 +70,8 @@ const Dropdown = ({ isOpen, children }) => {
7270
if (!isOpen) return null;
7371

7472
return ReactDOM.createPortal(
75-
<div className="dropdown">
76-
{children}
77-
</div>,
78-
document.body
73+
<div className="dropdown">{children}</div>,
74+
document.body,
7975
);
8076
};
8177
```
@@ -99,4 +95,3 @@ ReactDOM.createPortal(child, container);
9995
- [React Portals documentation](https://reactjs.org/docs/portals.html)
10096
- [Building a modal with React Portals](https://blog.logrocket.com/building-a-modal-with-react-portals/)
10197
- [Using React Portals for better accessibility](https://www.smashingmagazine.com/2020/03/react-portals-accessibility/)
102-

0 commit comments

Comments
 (0)