redux vs mobx vs vuex
상태 관리 라이브러리
reduxmobxvuexÄhnliche Pakete:

상태 관리 라이브러리

상태 관리 라이브러리는 애플리케이션의 상태를 효율적으로 관리하고 업데이트하기 위해 사용되는 도구입니다. 이 라이브러리들은 데이터의 흐름을 관리하고, UI와 상태 간의 동기화를 쉽게 해줍니다. MobX, Redux, Vuex는 각각의 설계 원칙과 사용 사례에 따라 다양한 방식으로 상태 관리를 제공합니다.

npm-Download-Trend

3 Jahre

GitHub Stars Ranking

Statistik-Detail

Paket
Downloads
Stars
Größe
Issues
Veröffentlichung
Lizenz
redux62,844,40661,441290 kB17vor 3 JahrenMIT
mobx4,632,75028,2194.89 MB19vor 3 TagenMIT
vuex2,445,56528,289271 kB144-MIT

Funktionsvergleich: redux vs mobx vs vuex

상태 관리 방식

  • redux:

    Redux는 단일 스토어를 사용하여 애플리케이션의 모든 상태를 중앙에서 관리합니다. 상태의 변경은 액션을 통해 이루어지며, 리듀서를 통해 상태를 업데이트합니다. 이 구조는 상태의 변화를 예측 가능하게 만들어 디버깅을 용이하게 합니다.

  • mobx:

    MobX는 반응형 상태 관리를 사용하여 상태의 변화를 자동으로 UI에 반영합니다. 상태가 변경되면 관련된 컴포넌트가 자동으로 업데이트됩니다. 이는 개발자가 상태 변화를 명시적으로 처리할 필요가 없음을 의미합니다.

  • vuex:

    Vuex는 Vue.js의 반응성을 활용하여 상태를 중앙 집중식으로 관리합니다. Vuex 스토어는 상태, 변이(mutations), 액션(actions), 게터(getters)로 구성되어 있으며, Vue 컴포넌트와의 통합이 원활합니다.

비동기 처리

  • redux:

    Redux는 미들웨어를 통해 비동기 작업을 처리합니다. Redux Thunk 또는 Redux Saga와 같은 미들웨어를 사용하여 비동기 액션을 쉽게 관리할 수 있습니다.

  • mobx:

    MobX는 비동기 처리를 위해 async/await를 지원합니다. 상태가 변경될 때 자동으로 UI가 업데이트되므로, 비동기 작업 후 상태를 수동으로 업데이트할 필요가 없습니다.

  • vuex:

    Vuex는 액션을 통해 비동기 작업을 처리합니다. 액션은 비동기 로직을 포함할 수 있으며, 이후 변이를 통해 상태를 업데이트합니다.

학습 곡선

  • redux:

    Redux는 개념이 명확하지만, 상태 관리 패턴이 복잡할 수 있어 학습 곡선이 다소 높습니다. 특히 미들웨어와 리듀서의 개념을 이해하는 데 시간이 걸릴 수 있습니다.

  • mobx:

    MobX는 직관적인 API와 간단한 개념으로 인해 상대적으로 학습 곡선이 낮습니다. 반응형 프로그래밍에 익숙한 개발자라면 쉽게 접근할 수 있습니다.

  • vuex:

    Vuex는 Vue.js와 밀접하게 통합되어 있어, Vue에 익숙한 개발자라면 쉽게 배울 수 있습니다. 그러나 상태 관리 패턴에 대한 이해가 필요합니다.

유연성

  • redux:

    Redux는 상태 관리의 일관성을 보장하지만, 구조가 엄격하여 유연성이 떨어질 수 있습니다. 그러나 미들웨어를 통해 다양한 기능을 확장할 수 있습니다.

  • mobx:

    MobX는 상태 관리에 있어 유연성을 제공합니다. 상태를 직접 수정할 수 있으며, 복잡한 구조 없이도 쉽게 사용할 수 있습니다.

  • vuex:

    Vuex는 Vue.js에 최적화되어 있으며, Vue의 반응성을 활용하여 상태를 관리합니다. 그러나 Vue 외의 다른 프레임워크와의 통합은 제한적입니다.

디버깅 용이성

  • redux:

    Redux는 상태의 변화를 액션을 통해 명확하게 추적할 수 있어, 디버깅이 용이합니다. Redux DevTools를 사용하면 상태의 변화를 시각적으로 확인할 수 있습니다.

  • mobx:

    MobX는 상태의 변화를 자동으로 추적하므로, 디버깅이 용이합니다. 상태 변경을 명시적으로 처리할 필요가 없어 코드가 간결해집니다.

  • vuex:

    Vuex는 Vue Devtools와 통합되어 상태의 변화를 쉽게 추적할 수 있습니다. 상태, 변이, 액션을 시각적으로 확인할 수 있어 디버깅이 용이합니다.

Wie man wählt: redux vs mobx vs vuex

  • redux:

    Redux는 예측 가능한 상태 관리를 제공하며, 상태의 변화를 명확하게 추적할 수 있습니다. 대규모 애플리케이션에서 복잡한 상태 관리를 필요로 할 때 유용합니다. 미들웨어를 통해 비동기 작업을 처리할 수 있어, 복잡한 비즈니스 로직이 필요한 경우에 적합합니다.

  • mobx:

    MobX는 반응형 프로그래밍을 지원하며, 상태를 자동으로 추적하고 UI에 반영합니다. 간단하고 직관적인 API를 제공하므로, 작은 프로젝트나 빠른 프로토타입 제작에 적합합니다. 복잡한 상태 관리가 필요하지 않은 경우에 선택하세요.

  • vuex:

    Vuex는 Vue.js 애플리케이션을 위한 상태 관리 패턴과 라이브러리입니다. Vue의 반응성을 활용하여 상태를 중앙 집중식으로 관리할 수 있으며, Vue 컴포넌트 간의 상태 공유가 용이합니다. Vue.js를 사용하는 프로젝트에서 선택하세요.

README für redux

Redux Logo

Redux is a predictable state container for JavaScript apps.

It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger.

You can use Redux together with React, or with any other view library. The Redux core is tiny (2kB, including dependencies), and has a rich ecosystem of addons.

Redux Toolkit is our official recommended approach for writing Redux logic. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications.

GitHub Workflow Status npm version npm downloads redux channel on discord

Installation

Create a React Redux App

The recommended way to start new apps with React and Redux Toolkit is by using our official Redux Toolkit + TS template for Vite, or by creating a new Next.js project using Next's with-redux template.

Both of these already have Redux Toolkit and React-Redux configured appropriately for that build tool, and come with a small example app that demonstrates how to use several of Redux Toolkit's features.

# Vite with our Redux+TS template
# (using the `degit` tool to clone and extract the template)
npx degit reduxjs/redux-templates/packages/vite-template-redux my-app

# Next.js using the `with-redux` template
npx create-next-app --example with-redux my-app

We do not currently have official React Native templates, but recommend these templates for standard React Native and for Expo:

npm install @reduxjs/toolkit react-redux

For the Redux core library by itself:

npm install redux

For more details, see the Installation docs page.

Documentation

The Redux core docs are located at https://redux.js.org, and include the full Redux tutorials, as well usage guides on general Redux patterns:

The Redux Toolkit docs are available at https://redux-toolkit.js.org, including API references and usage guides for all of the APIs included in Redux Toolkit.

Learn Redux

Redux Essentials Tutorial

The Redux Essentials tutorial is a "top-down" tutorial that teaches "how to use Redux the right way", using our latest recommended APIs and best practices. We recommend starting there.

Redux Fundamentals Tutorial

The Redux Fundamentals tutorial is a "bottom-up" tutorial that teaches "how Redux works" from first principles and without any abstractions, and why standard Redux usage patterns exist.

Help and Discussion

The #redux channel of the Reactiflux Discord community is our official resource for all questions related to learning and using Redux. Reactiflux is a great place to hang out, ask questions, and learn - please come and join us there!

Before Proceeding Further

Redux is a valuable tool for organizing your state, but you should also consider whether it's appropriate for your situation. Please don't use Redux just because someone said you should - instead, please take some time to understand the potential benefits and tradeoffs of using it.

Here are some suggestions on when it makes sense to use Redux:

  • You have reasonable amounts of data changing over time
  • You need a single source of truth for your state
  • You find that keeping all your state in a top-level component is no longer sufficient

Yes, these guidelines are subjective and vague, but this is for a good reason. The point at which you should integrate Redux into your application is different for every user and different for every application.

For more thoughts on how Redux is meant to be used, please see:

Basic Example

The whole global state of your app is stored in an object tree inside a single store. The only way to change the state tree is to create an action, an object describing what happened, and dispatch it to the store. To specify how state gets updated in response to an action, you write pure reducer functions that calculate a new state based on the old state and the action.

Redux Toolkit simplifies the process of writing Redux logic and setting up the store. With Redux Toolkit, the basic app logic looks like:

import { createSlice, configureStore } from '@reduxjs/toolkit'

const counterSlice = createSlice({
  name: 'counter',
  initialState: {
    value: 0
  },
  reducers: {
    incremented: state => {
      // Redux Toolkit allows us to write "mutating" logic in reducers. It
      // doesn't actually mutate the state because it uses the Immer library,
      // which detects changes to a "draft state" and produces a brand new
      // immutable state based off those changes
      state.value += 1
    },
    decremented: state => {
      state.value -= 1
    }
  }
})

export const { incremented, decremented } = counterSlice.actions

const store = configureStore({
  reducer: counterSlice.reducer
})

// Can still subscribe to the store
store.subscribe(() => console.log(store.getState()))

// Still pass action objects to `dispatch`, but they're created for us
store.dispatch(incremented())
// {value: 1}
store.dispatch(incremented())
// {value: 2}
store.dispatch(decremented())
// {value: 1}

Redux Toolkit allows us to write shorter logic that's easier to read, while still following the original core Redux behavior and data flow.

Logo

You can find the official logo on GitHub.

Change Log

This project adheres to Semantic Versioning. Every release, along with the migration instructions, is documented on the GitHub Releases page.

License

MIT