и посмотреть медиа
Frontend | Interview questions
и посмотреть медиа
Interview questions frontend randomly.
Interview questions frontend randomly.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Collection of frontend questions: JavaScript, frameworks, performance, accessibility. Detailed answers will help confidently pass interviews.
🤔 Какие есть альтернативы у redux? Redux – мощный инструмент, но не всегда он необходим. Существует множество альтернатив, каждая из которых подходит для разных сценариев. 🚩React Context API + useReducer Подходит для небольших и средних приложений Встроено в React (не требует установки дополнительных библиотек) useContext` позволяет передавать данные по дереву компонентов без "прокидывания" через props useReducer работает как Redux, но проще const AuthContext = createContext(); function authReducer(state, action) { switch (action.type) { case "LOGIN": return { ...state, isAuthenticated: true, user: action.payload }; case "LOGOUT": return { ...state, isAuthenticated: false, user: null }; default: return state; } } function AuthProvider({ children }) { const [state, dispatch] = useReducer(authReducer, { isAuthenticated: false, user: null, }); return ( {children} ); } function LoginButton() { const { dispatch } = useContext(AuthContext); return ( dispatch({ type: "LOGIN", payload: "Иван" })}> Войти ); } 🚩Zustand Проще Redux, но с теми же возможностями Нет лишних actions и reducers, только функции import { create } from "zustand"; const useStore = create((set) => ({ count: 0, increment: () => set((state) => ({ count: state.count + 1 })), })); function Counter() { const { count, increment } = useStore(); return Счетчик: {count}; } 🚩Recoil Идеален для React-приложений Гибче, чем Redux, с концепцией "атомов" (раздельные состояния) import { atom, useRecoilState } from "recoil"; const countState = atom({ key: "count", default: 0, }); function Counter() { const [count, setCount] = useRecoilState(countState); return setCount(count + 1)}>Счетчик: {count}; } 🚩Jotai Напоминает Recoil, но без сложных концепций Поддерживает React Suspense и асинхронные состояния import { atom, useAtom } from "jotai"; const countAtom = atom(0); function Counter() { const [count, setCount] = useAtom(countAtom); return setCount(count + 1)}>Счетчик: {count}; } 🚩MobX Автоматически отслеживает изменения состояния Удобен для сложных приложений import { makeAutoObservable } from "mobx"; import { observer } from "mobx-react-lite"; class CounterStore { count = 0; constructor() { makeAutoObservable(this); } increment() { this.count++; } } const store = new CounterStore(); const Counter = observer(() => ( store.increment()}>Счетчик: {store.count} )); 🚩XState Подходит для сложных логик (например, UI-анимаций, состояний формы) Удобно описывать последовательности действий import { createMachine, interpret } from "xstate"; const toggleMachine = createMachine({ id: "toggle", initial: "inactive", states: { inactive: { on: { TOGGLE: "active" } }, active: { on: { TOGGLE: "inactive" } }, }, }); const service = interpret(toggleMachine).start(); service.send("TOGGLE"); // Меняет состояние Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!