From 55c4ae7d5361665a5c7aa4d504275966e9ac433d Mon Sep 17 00:00:00 2001 From: Laktionov Anton Date: Thu, 11 Jun 2026 20:43:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D0=BB=D0=B0=D0=BC=D0=BF=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 36 +++++++++++++++++++++++++--- package.json | 3 ++- src/App.jsx | 61 +++++++++++++++++------------------------------ 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4053aec..6df26b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "dependencies": { "immer": "^11.1.8", "react": "^19.1.0", - "react-dom": "^19.1.0" + "react-dom": "^19.1.0", + "zustand": "^5.0.14" }, "devDependencies": { "@eslint/js": "^9.25.0", @@ -1368,7 +1369,7 @@ "version": "19.1.6", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.1.6.tgz", "integrity": "sha512-JeG0rEWak0N6Itr6QUx+X60uQmN+5t3j9r/OVDtWzFXKaj6kD1BwJzOksD0FF6iWxZlbE1kB0q9vtnU2ekqa1Q==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "csstype": "^3.0.2" @@ -1620,7 +1621,7 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/debug": { @@ -2805,6 +2806,35 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zustand": { + "version": "5.0.14", + "resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.14.tgz", + "integrity": "sha512-/8tAspM5LMPr28b3fwLYrtdj77ECpfZviaP75CMTnwO8ISyaE4GDIG/9rDDYq/cH9D2Xw2A2RXglLInmVBQB/g==", + "license": "MIT", + "engines": { + "node": ">=12.20.0" + }, + "peerDependencies": { + "@types/react": ">=18.0.0", + "immer": ">=9.0.6", + "react": ">=18.0.0", + "use-sync-external-store": ">=1.2.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "immer": { + "optional": true + }, + "react": { + "optional": true + }, + "use-sync-external-store": { + "optional": true + } + } } } } diff --git a/package.json b/package.json index 46f4b06..b124c6e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "dependencies": { "immer": "^11.1.8", "react": "^19.1.0", - "react-dom": "^19.1.0" + "react-dom": "^19.1.0", + "zustand": "^5.0.14" }, "devDependencies": { "@eslint/js": "^9.25.0", diff --git a/src/App.jsx b/src/App.jsx index 390d943..0126d06 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,49 +1,32 @@ import React, { useState, useEffect } from 'react' -import { produce } from 'immer' +import { create } from 'zustand' + +const useLightStore = create(set => ({ + isLightOn: false, + toggleLight: () => set(state => ({isLightOn: !state.isLightOn})), + turnOn: () => set({isLightOn:true}), + turnOff: () => set({isLightOn:false}), +})) + +function LightButton() { + const toggleLight = useLightStore(state => state.toggleLight) + return () +} + +function LightOff() { + const lightOff = useLightStore(state => state.turnOff) + return () +} function App() { - const [tasks,setTasks] = useState([]) - const [input,setInput] = useState('') + const isLightOn = useLightStore(state => state.isLightOn) - const addTask = () => { - if(!input.trim()) return - - setTasks(currentTasks => produce(currentTasks, draft => { - draft.push({ - id: Date.now(), - text: input.trim(), - done: false - }) - })) - setInput('') - } - const toggleTask = id => { - setTasks(currentTask => produce(currentTask, draft => { - const task = draft.find(t => t.id === id) - if(task) { - task.done = !task.done - } - })) - } - const removeTask = id => { - setTasks(currentTask => produce(currentTask, draft => { - const index = draft.findIndex(t => t.id === id) - if (index !== -1) - draft.splice(index,1) - })) - } return ( <>

Практика по созданию списка задач

- setInput(e.target.value)} /> - - +
Лампочка: {isLightOn ? 'Включена' : 'Выключена'}
+ + ) }