- Создаем страницу, например
/page4
- На страницу помещаем два компонента
- В каждом компоненте рендерим один текстовый инпут
- Изменение текста в одном инпуте должно приводить к немедленному изменению текста в другом и наоборот
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
import { useState, useEffect } from 'react'; | |
import { useSelector, useDispatch } from 'react-redux'; | |
import { NewTask } from './NewTask' | |
import { TaskList } from './TaskList' | |
import { TodosSlice } from '../../slices/todo'; | |
export const Todos = () => { | |
const { | |
selectors: { getTasks }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
import { createSlice } from '@reduxjs/toolkit' | |
const localStorageKey = 'todos/items'; | |
const initialState = () => { | |
try { | |
const storageTasks = JSON.parse( | |
localStorage.getItem(localStorageKey)); | |
return { tasks: storageTasks } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState, useRef } from 'react'; | |
import { useParams } from 'react-router-dom' | |
import classes from './page-user.module.css' | |
const InputRow = ({ id, title, value, setValue }) => { | |
return ( | |
<div className={ classes.row }> | |
<label htmlFor={ id }>{ title }</label> | |
<input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
import { useParams } from 'react-router-dom' | |
import classes from './page-user.module.css' | |
export const PageUser = () => { | |
const { id } = useParams(); | |
const [ user, setUser ] = useState({}); | |
useEffect(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import classes from './page.module.css' | |
import { useRef, useState } from 'react' | |
export const PageFetch = () => { | |
const urlRef = useRef(""); | |
const resultRef = useRef(""); | |
const bodyRef = useRef("{}"); | |
const [method, setMethod] = useState("GET"); | |
const hasBody = ["POST", "PUT"].includes(method); |
- Общее замечание: надо привыкать раскладывать компоненты по отдельным каталогам и файлам
const body
- НЕ НАДО называть компоненты именами существующих тегов. Именно для этого их обычно называют с БОЛЬШОЙ буквы
- Тег body как правило НЕ заменяют компонентом, просто потому, что первый же компонент находится внутри body