REACT_LIB Telegram 694
πŸ”§ Π¨ΠΏΠ°Ρ€Π³Π°Π»ΠΊΠ° ΠΏΠΎ Π±Π°Π·ΠΎΠ²Ρ‹ΠΌ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°ΠΌ React



// Π˜ΠΌΠΏΠΎΡ€Ρ‚ React ΠΈ Ρ€ΠΎΡƒΡ‚Π΅Ρ€Π°
import React, { useState, useEffect, createContext, useContext } from 'react';
import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';

// 1. Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ контСкста
const MyContext = createContext();

// 2. ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ с Context ΠΈ useEffect
function Welcome() {
const contextValue = useContext(MyContext);

useEffect(() => {
console.log("Welcome component mounted or updated");
return () => console.log("Welcome component unmounted");
}, []);

return <h1>{contextValue}</h1>;
}

// 3. УправляСмая Ρ„ΠΎΡ€ΠΌΠ°
function FormComponent() {
const [inputValue, setInputValue] = useState('');
const handleChange = (e) => setInputValue(e.target.value);

return (
<div>
<h2>Controlled Form</h2>
<input type="text" value={inputValue} onChange={handleChange} />
<p>Input Value: {inputValue}</p>
</div>
);
}

// 4. Π‘Ρ‡Ρ‘Ρ‚Ρ‡ΠΈΠΊ с состояниСм ΠΈ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠΌ
function Counter() {
const [count, setCount] = useState(0);

return (
<div>
<h2>Counter</h2>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}

// 5. Π Π΅Π½Π΄Π΅Ρ€ списка
function FruitList() {
const fruits = ['Apple', 'Banana', 'Orange'];
return (
<div>
<h2>Fruit List</h2>
<ul>
{fruits.map((fruit, index) => (
<li key={index}>{fruit}</li>
))}
</ul>
</div>
);
}

// 6. Условный Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΠ½Π³
function ConditionalRender({ isLoggedIn }) {
return (
<div>
<h2>Conditional Rendering</h2>
{isLoggedIn ? <p>Welcome back!</p> : <p>Please log in.</p>}
</div>
);
}

// 7. Навигация
function Navigation() {
return (
<nav>
<Link to="/">Home</Link> | <Link to="/form">Form</Link> | <Link to="/counter">Counter</Link> | <Link to="/fruits">Fruits</Link>
</nav>
);
}

// 8. Основной App с Router и Context
function App() {
return (
<MyContext.Provider value="Hello, Context!">
<Router>
<div style={{ padding: '20px', fontFamily: 'Arial' }}>
<Navigation />
<Switch>
<Route path="/" exact>
<Welcome />
<ConditionalRender isLoggedIn={true} />
</Route>
<Route path="/form" component={FormComponent} />
<Route path="/counter" component={Counter} />
<Route path="/fruits" component={FruitList} />
</Switch>
</div>
</Router>
</MyContext.Provider>
);
}

export default App;


✍️ @React_lib
πŸ‘6



tgoop.com/React_lib/694
Create:
Last Update:

πŸ”§ Π¨ΠΏΠ°Ρ€Π³Π°Π»ΠΊΠ° ΠΏΠΎ Π±Π°Π·ΠΎΠ²Ρ‹ΠΌ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚Π°ΠΌ React



// Π˜ΠΌΠΏΠΎΡ€Ρ‚ React ΠΈ Ρ€ΠΎΡƒΡ‚Π΅Ρ€Π°
import React, { useState, useEffect, createContext, useContext } from 'react';
import { BrowserRouter as Router, Route, Switch, Link } from 'react-router-dom';

// 1. Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ контСкста
const MyContext = createContext();

// 2. ΠšΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ с Context ΠΈ useEffect
function Welcome() {
const contextValue = useContext(MyContext);

useEffect(() => {
console.log("Welcome component mounted or updated");
return () => console.log("Welcome component unmounted");
}, []);

return <h1>{contextValue}</h1>;
}

// 3. УправляСмая Ρ„ΠΎΡ€ΠΌΠ°
function FormComponent() {
const [inputValue, setInputValue] = useState('');
const handleChange = (e) => setInputValue(e.target.value);

return (
<div>
<h2>Controlled Form</h2>
<input type="text" value={inputValue} onChange={handleChange} />
<p>Input Value: {inputValue}</p>
</div>
);
}

// 4. Π‘Ρ‡Ρ‘Ρ‚Ρ‡ΠΈΠΊ с состояниСм ΠΈ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠΌ
function Counter() {
const [count, setCount] = useState(0);

return (
<div>
<h2>Counter</h2>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}

// 5. Π Π΅Π½Π΄Π΅Ρ€ списка
function FruitList() {
const fruits = ['Apple', 'Banana', 'Orange'];
return (
<div>
<h2>Fruit List</h2>
<ul>
{fruits.map((fruit, index) => (
<li key={index}>{fruit}</li>
))}
</ul>
</div>
);
}

// 6. Условный Ρ€Π΅Π½Π΄Π΅Ρ€ΠΈΠ½Π³
function ConditionalRender({ isLoggedIn }) {
return (
<div>
<h2>Conditional Rendering</h2>
{isLoggedIn ? <p>Welcome back!</p> : <p>Please log in.</p>}
</div>
);
}

// 7. Навигация
function Navigation() {
return (
<nav>
<Link to="/">Home</Link> | <Link to="/form">Form</Link> | <Link to="/counter">Counter</Link> | <Link to="/fruits">Fruits</Link>
</nav>
);
}

// 8. Основной App с Router и Context
function App() {
return (
<MyContext.Provider value="Hello, Context!">
<Router>
<div style={{ padding: '20px', fontFamily: 'Arial' }}>
<Navigation />
<Switch>
<Route path="/" exact>
<Welcome />
<ConditionalRender isLoggedIn={true} />
</Route>
<Route path="/form" component={FormComponent} />
<Route path="/counter" component={Counter} />
<Route path="/fruits" component={FruitList} />
</Switch>
</div>
</Router>
</MyContext.Provider>
);
}

export default App;


✍️ @React_lib

BY React


Share with your friend now:
tgoop.com/React_lib/694

View MORE
Open in Telegram


Telegram News

Date: |

Hashtags The channel also called on people to turn out for illegal assemblies and listed the things that participants should bring along with them, showing prior planning was in the works for riots. The messages also incited people to hurl toxic gas bombs at police and MTR stations, he added. How to create a business channel on Telegram? (Tutorial) How to create a business channel on Telegram? (Tutorial) Private channels are only accessible to subscribers and don’t appear in public searches. To join a private channel, you need to receive a link from the owner (administrator). A private channel is an excellent solution for companies and teams. You can also use this type of channel to write down personal notes, reflections, etc. By the way, you can make your private channel public at any moment.
from us


Telegram React
FROM American