Skip to content

Commit 322ccaa

Browse files
committed
fixed issues
1 parent 1eaf6da commit 322ccaa

File tree

7 files changed

+41
-48
lines changed

7 files changed

+41
-48
lines changed

courses/react-js/intermidiate-level/managing-complex-uis/App.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

courses/react-js/intermidiate-level/managing-complex-uis/ChildComponent.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useState } from "react";
2+
3+
/**
4+
* @module Counter
5+
* @param {number} count - The count of the counter
6+
* @param {function} setCount - The function to set the count
7+
* @returns {JSX.Element} - The JSX code for the Counter component
8+
*/
9+
10+
function Counter() {
11+
const [count, setCount] = useState(0);
12+
13+
return (
14+
<div>
15+
<h1>Count: {count}</h1>
16+
<div>
17+
<h2>Parent Component</h2>
18+
<p>Count: {count}</p>
19+
<div>
20+
<h3>Child Component</h3>
21+
<button
22+
onClick={(function () {
23+
setCount(count + 1);
24+
})()}
25+
>
26+
Increment Count
27+
</button>
28+
</div>
29+
</div>
30+
</div>
31+
);
32+
}
33+
34+
export default Counter;

courses/react-js/intermidiate-level/managing-complex-uis/ParentComponent.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

courses/react-js/intermidiate-level/managing-complex-uis/lesson_1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: "Learn how to lift state up in React to manage shared state across
77
tags: [courses, react-js, intermediate-level, state-management, lifting-state-up]
88
---
99

10-
import App from './App';
10+
import Counter from './Counter';
1111

1212
In React applications, managing shared state between components can be challenging, especially when components are not directly related in the component tree. Lifting state up is a common pattern in React that allows you to manage shared state in a parent component and pass it down to child components as props. This lesson will introduce you to the concept of lifting state up and show you how to use it to share state between components in your React applications.
1313

@@ -80,7 +80,7 @@ Here's an example of lifting state up in a React application:
8080
In this example, we have an `App` component that manages the `count` state using the `useState` hook. The `App` component passes the `count` state and an `incrementCount` function down to the `ParentComponent` as props. The `ParentComponent` then passes the `incrementCount` function down to the `ChildComponent` as a prop. When the `ChildComponent` button is clicked, it calls the `incrementCount` function to update the `count` state in the `App` component.
8181

8282
<BrowserWindow>
83-
<App />
83+
<Counter />
8484
</BrowserWindow>
8585

8686
By lifting the `count` state up to the `App` component, we can share the state between the `ParentComponent` and `ChildComponent` without having to pass the state through multiple levels of components. This pattern helps keep the application's data in sync and makes it easier to manage shared state across components.

docs/react/back-end-integration/DataFetcher.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import axios from 'axios';
33

44
const DataFetcher = () => {

docs/react/back-end-integration/FetchDataComponent.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import { useState, useEffect } from 'react';
22

33
function FetchDataComponent() {
44
const [userData, setUserData] = useState(null);
@@ -8,6 +8,9 @@ function FetchDataComponent() {
88
async function fetchData() {
99
try {
1010
const response = await fetch('https://api.github.com/users/Ajay-Dhangar');
11+
if (!response.ok) {
12+
throw new Error('Failed to fetch data');
13+
}
1114
const data = await response.json();
1215
setUserData(data);
1316
} catch (error) {

0 commit comments

Comments
 (0)