diff --git a/src/App.jsx b/src/App.jsx index 0126d06..13fe93a 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,32 +1,24 @@ import React, { useState, useEffect } from 'react' import { create } from 'zustand' -const useLightStore = create(set => ({ - isLightOn: false, - toggleLight: () => set(state => ({isLightOn: !state.isLightOn})), - turnOn: () => set({isLightOn:true}), - turnOff: () => set({isLightOn:false}), +const useUserStore = create(set => ({ + fetchUser: async userId => { + set({ isLoading: true, error: null}) + try { + const response = await fetch(`api/users/${userId}`) + const user = await response.json() + set({user, isLoading: false}) + } catch (error) { + set({error: error.message, isLoading: false}) + } + } })) -function LightButton() { - const toggleLight = useLightStore(state => state.toggleLight) - return () -} - -function LightOff() { - const lightOff = useLightStore(state => state.turnOff) - return () -} function App() { - const isLightOn = useLightStore(state => state.isLightOn) - return ( <>

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

-
Лампочка: {isLightOn ? 'Включена' : 'Выключена'}
- - ) }