What are the differences between Redux and Flux in ReactJS ?
Last Updated :
23 Jul, 2025
During the phase of applications or software development, we gather the requirements of customers to create a solution to solve the problem of customers or businesses. To solve problems we rely on different technologies and architecture patterns. for a long time, developers were using MVC (Model-View-Controller) pattern. As we know that after every month new technologies come into the market with new features which replace previous ones. So the same way development team of Facebook come up with important changes and release flux which becomes an alternative option for MVC architecture. and after flux, there has been another framework Redux comes into the market. Let's discuss Redux vs Flux in this article.
Flux: Flux is the application architecture or we can say JavaScript architecture that uses for building client-side web applications or UI for client applications. you can start using flux without a lot of new code. flux overcome the drawbacks of MVC such as instability and complexity.
Example: In this example, we create a TODO list application. This example contains functionality that you can add a task in the TODO list along with you can remove the list of tasks.
Step 1: Create a new react app using the below commands.
devendra@root:~/Desktop$ npx create-react-app todoapp
devendra@root:~/Desktop/todoapp$ npm install redux react-redux --save
Step 2: Create a folder structure in your code editor as given below in the screenshot you can create files manually or using commands as well.
Project Structure:
todo app folder structure
Step 3 (Actions): Actions are things that happen during the lifetime of your application. In our application when the user clicks on create button a function CRAETE_TODO will call and a new task will be added to the list. The same DELETE_TODO function will perform a delete action when the Delete button is clicked. This is an example of the Action component.
TodoActions.js
JavaScript
import dispatcher from "../dispatcher";
/* Create task function */
export function createTodo(text) {
dispatcher.dispatch({
type: "CREATE_TODO",
text,
});
}
/* Delete task function */
export function deleteTodo(id) {
dispatcher.dispatch({
type: "DELETE_TODO",
id,
});
}
Step 4: Dispatchers
Think of the Dispatcher as a router. Actions are sent to the Dispatcher who calls the appropriate callbacks.
dispatcher.js
JavaScript
import { Dispatcher } from "flux";
export default new Dispatcher;
Step 5 (Store):
A store is a place that holds the app's state. It is very easy to create a store once you have reducers. We are passing store property to the provider element, which wraps our route component.
JavaScript
import { EventEmitter } from 'events';
import dispatcher from '../dispatcher';
class TodoStore extends EventEmitter {
constructor() {
super();
this.todos = [
{
id: 16561,
text: 'hello'
},
{
id: 16562,
text: 'another todo'
},
];
}
createTodo(text) {
const id = Date.now();
this.todos.push({
id,
text
});
this.emit('change');
}
deleteTodo(id) {
this.todos = this.todos.filter((elm) => {
return (elm.id != id);
});
this.emit('change');
}
getAll() {
return this.todos;
}
handleActions(action) {
switch (action.type) {
case 'CREATE_TODO': {
this.createTodo(action.text);
break;
}
case 'DELETE_TODO': {
this.deleteTodo(action.id);
break;
}
}
}
}
const todoStore = new TodoStore();
dispatcher.register(todoStore.handleActions.bind(todoStore));
export default todoStore;
Step 6 (Root Component): The index.js component is the root component of the app. Only the root component should be aware of a redux. The important part to notice is the connect function which is used for connecting our root component App to the store. This function takes a select function as an argument. The select function takes the state from the store and returns the props (visibleTodos) that we can use in our components.
Todolist.js
JavaScript
import React from 'react';
import Todo from '../components/Todo';
import TodoStore from '../stores/TodoStore.js';
import * as TodoActions from '../actions/TodoActions';
export default class Todolist extends React.Component {
constructor() {
super();
this.state = {
todos: TodoStore.getAll(),
};
this.inputContent = '';
}
// We start listening to the store changes
componentWillMount() {
TodoStore.on("change", () => {
this.setState({
todos: TodoStore.getAll(),
});
});
}
render() {
const TodoComp = this.state.todos.map(todo => {
return <Todo key={todo.id} {...todo} />;
});
return (
<div>
<h1> GFG Todo list</h1>
<input type="text" onChange=
{(evt) => this.inputContent = evt.target.value} />
<button onClick={() => TodoActions
.createTodo(this.inputContent)}>Create!</button>
<ul>{TodoComp}</ul>
</div>
);
}
}
Step 7: Now we will delete the task component.
Todo.js
JavaScript
import React from "react";
import * as TodoActions from '../actions/TodoActions';
export default class Todo extends React.Component {
render() {
return (
<li>
<span>{this.props.text}</span>
<button onClick={() => TodoActions
.deleteTodo(this.props.id)}>delete</button>
</li>
);
}
}
Step 8: Other components
index.js
JavaScript
import React from 'react';
import { render } from 'react-dom';
import Todolist from './pages/Todolist';
const app = document.getElementById('root');
// render(React.createElement(Layout), app);
render(<Todolist />, app);
Step to run application: Open the terminal and type the following command.
npm start
Output:Create button will add a task to Todo list, similarly Delete button removes the task from the Todo list

Redux: Redux is a predictable state container for JavaScript apps. Dan Abramov & Andrew Clark developed Redux in 2015. Redux itself library that can be used with any UI layer or framework, including React, Angular, Ember, and vanilla JS. Redux can be used with React. both are independent of each other. Redux is a state managing library used in JavaScript apps. It simply manages the state of your application or in other words, it is used to manage the data of the application. It is used with a library like React.
Example: Now we will see a simple example counter using react-redux. In this example we store a state of button clicks and used that states for further buttons to click for example we create four buttons increment (+), decrement (-), increment if odd, increment async.
- increment (+), decrement (-): these two buttons will increment click by +1 and -1
- increment if odd: this button will only increment click if previous two buttons (+)and (-) click is odd i.e. if the click is 7 then only this button will increment by +1 and now clicks will be 8 otherwise this will not increment if previous buttons (+) and (-) clicks were 6 because 6 is even and increment if odd button only clicks when the previous state is odd click.
- increment async: This button will increment click after halt or wait of 1000 mili. sec.
Below is the step by step implementation:
Step 1: Create a new react app using the below commands.
npx create-react-app counterproject
npm install redux react-redux --save
Step 2: Create all required Files and Folders.
Project Structure: It will look like the following.
files and folders
Step 3: Counter.js is a Presentational Component, which is concerned with how things look such as markup, styles. It receives data and invokes callbacks exclusively via props. It does not know where the data comes from or how to change it. It only renders what is given to them. This is the root component for the counter to render everything in UI.
Counter.js
JavaScript
import React, { Component } from 'react'
import PropTypes from 'prop-types'
class Counter extends Component {
constructor(props) {
super(props);
this.incrementAsync = this.incrementAsync.bind(this);
this.incrementIfOdd = this.incrementIfOdd.bind(this);
}
incrementIfOdd() {
if (this.props.value % 2 !== 0) {
this.props.onIncrement()
}
}
incrementAsync() {
setTimeout(this.props.onIncrement, 1000)
}
render() {
const { value, onIncrement, onDecrement } = this.props
return (
<p>
<h1>GeeksForGeeks Counter Example</h1>
Clicked: {value} times
{' '}
<button onClick={onIncrement}>
+
</button>
{' '}
<button onClick={onDecrement}>
-
</button>
{' '}
<button onClick={this.incrementIfOdd}>
Increment if odd
</button>
{' '}
<button onClick={this.incrementAsync}>
Increment async
</button>
</p>
)
}
}
Counter.propTypes = {
value: PropTypes.number.isRequired,
onIncrement: PropTypes.func.isRequired,
onDecrement: PropTypes.func.isRequired
}
export default Counter
Step 4: Counter.spec.js contains what to change when particular buttons of components are clicked.
JavaScript
import React from 'react'
import { shallow } from 'enzyme'
import Counter from './Counter'
function setup(value = 0) {
const actions = {
onIncrement: jest.fn(),
onDecrement: jest.fn()
}
const component = shallow(
<Counter value={value} {...actions} />
)
return {
component: component,
actions: actions,
buttons: component.find('button'),
p: component.find('p')
}
}
describe('Counter component', () => {
it('should display count', () => {
const { p } = setup()
expect(p.text()).toMatch(/^Clicked: 0 times/)
})
it('first button should call onIncrement', () => {
const { buttons, actions } = setup()
buttons.at(0).simulate('click')
expect(actions.onIncrement).toBeCalled()
})
it('second button should call onDecrement', () => {
const { buttons, actions } = setup()
buttons.at(1).simulate('click')
expect(actions.onDecrement).toBeCalled()
})
it('third button should not call onIncrement if the counter is even', () => {
const { buttons, actions } = setup(42)
buttons.at(2).simulate('click')
expect(actions.onIncrement).not.toBeCalled()
})
it('third button should call onIncrement if the counter is odd', () => {
const { buttons, actions } = setup(43)
buttons.at(2).simulate('click')
expect(actions.onIncrement).toBeCalled()
})
it('third button should call onIncrement if the counter is
odd and negative', () => {
const { buttons, actions } = setup(-43)
buttons.at(2).simulate('click')
expect(actions.onIncrement).toBeCalled()
})
it('fourth button should call onIncrement in a second', (done) => {
const { buttons, actions } = setup()
buttons.at(3).simulate('click')
setTimeout(() => {
expect(actions.onIncrement).toBeCalled()
done()
}, 1000)
})
})
Step 4: Reducers
This is a reducer, a function that takes a current state value and an action object describing "what happened", and returns a new state value. A reducer's function signature is: (state, action) => newState. it means a reducer function takes two parameters state and action. The Redux state should contain only plain JS objects, arrays, and primitives. The root state value is usually an object. It's important that you should not mutate the state object, but return a new object if the state changes. You can use any conditional logic you want in a reducer. In this example, we use a switch statement, but it's not required.
index.js
JavaScript
export default (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1
case 'DECREMENT':
return state - 1
default:
return state
}
}
Index.spec.js
JavaScript
import counter from './index'
describe('reducers', () => {
describe('counter', () => {
it('should provide the initial state', () => {
expect(counter(undefined, {})).toBe(0)
})
it('should handle INCREMENT action', () => {
expect(counter(1, { type: 'INCREMENT' })).toBe(2)
})
it('should handle DECREMENT action', () => {
expect(counter(1, { type: 'DECREMENT' })).toBe(0)
})
it('should ignore unknown actions', () => {
expect(counter(1, { type: 'unknown' })).toBe(1)
})
})
})
Step 5: Store
All container components need access to the Redux Store to subscribe to it. For this, we need to pass it(store) as a prop to every container component. However, it gets tedious. So we recommend using a special React Redux component called which makes the store available to all container components without passing it explicitly. It is used once when you render the root component.
index.js
JavaScript
import React from 'react'
import ReactDOM from 'react-dom'
import { createStore } from 'redux'
import Counter from './components/Counter'
import counter from './reducers'
const store = createStore(counter)
const rootEl = document.getElementById('root')
const render = () => ReactDOM.render(
<Counter
value={store.getState()}
onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
onDecrement={() => store.dispatch({ type: 'DECREMENT' })}
/>,
rootEl
)
render()
store.subscribe(render)
Step to run the application: Open the terminal and type the following command.
npm start
Output:

Difference between Redux and Flux:
Sr.no |
Redux
|
Flux
|
---|
1. | It was developed by Dan Abramov & Andrew Clark. | It was developed by Facebook. |
2. | It is an Open-source JavaScript library used for creating the UI. | It is Application architecture designed to build client-side web apps. |
3. |
Redux has mainly two components
|
Flux has main four components :
- Action
- Dispatcher
- Store
- View
|
4. | Redux does not have any dispatcher. | Flux has a single dispatcher. |
5. | Redux has only a single store in the application. | Flux has multiple stores in one application. |
6. | In Redux, Data logics are in the reducers. | In flux, Data logic is in store. |
7. | In Redux store’s state cannot be mutable | In flux store’s state can be mutable. |
8. |  |  |
Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability.React.jsWhy Use React?Before React, web development faced issues like slow DOM updates
8 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDom is a core react package that provides methods to interact with the Document Object Model or DOM. This package allows developers to access and modify the DOM. Let's see in brief what is the need to have the package. Table of ContentWhat is ReactDOM ?How to use ReactDOM ?Why ReactDOM is used
3 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
6 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsReact Lists are used to display a collection of similar data items like an array of objects and menu items. It allows us to dynamically render the array elements and display repetitive data.Rendering List in ReactTo render a list in React, we will use the JavaScript array map() function. We will ite
5 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. In this article, we'll explore ReactJS keys, understand their importance, how the
5 min read
Components in React
React ComponentsIn React, React components are independent, reusable building blocks in a React application that define what gets displayed on the UI. They accept inputs called props and return React elements describing the UI.In this article, we will explore the basics of React components, props, state, and render
4 min read
ReactJS Functional ComponentsIn ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.What are Reactjs Functio
5 min read
React Class ComponentsClass components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
4 min read
ReactJS Pure ComponentsReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
4 min read
ReactJS Container and Presentational Pattern in ComponentsIn this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
2 min read
ReactJS PropTypesIn ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem. Since in the latest version of the React 19, PropeTypes has been removed. What is ReactJS PropTypes?PropTypes is a tool in React that he
5 min read
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects