- Создаем страницу, например
/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 classes from './NewTask.module.css' | |
import { TodosSlice } from '../../slices/todo'; | |
import { useDispatch } from 'react-redux' | |
export const NewTask = ({ addTask }) => { | |
const { actions: { appendTask } } = TodosSlice; | |
const dispatch = useDispatch(); | |
const handleEnter = (e) => { | |
if (e.key === 'Enter') { |
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 { useDispatch } from 'react-redux'; | |
import { TodosSlice } from '../../slices/todo' | |
import classes from './Task.module.css' | |
import clsx from 'clsx' | |
export const Task = ({ task }) => { | |
const { actions: { removeTask, toggleTask } } = TodosSlice; | |
const dispatch = useDispatch(); | |
return ( |
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 { Task } from './Task' | |
import { TodosSlice } from '../../slices/todo'; | |
import { useSelector } from 'react-redux'; | |
export const TaskList = () => { | |
const { selectors: { getTasks } } = TodosSlice; | |
const tasks = useSelector(getTasks); | |
return ( | |
<ul> |
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); |