min read
November 8, 2019
October 30, 2018

Drag & Drop Reorderable Grid List With REACT + REDUX

Drag & Drop Reorderable Grid List With REACT + REDUX
Table of contents

Generally, a lot of devs face problem when it comes to drag and drop functionality implementation and its integration with the Redux states is a big pain. Well, we all can do in some way with some workarounds but what should be the actual process of its implementation and what coding patterns to be followed to make it as performant and as reusable as possible. 

We are going to use React-sortable-hoc, a cool React Lib, available to implement the drag & drop, is going to be our base of the implementations. We will also see how the data is sent to the Sortable component through Redux store and how the corresponding data is updated on reordering of the list.


Let’s Get Started!

  • First, you need to set up the Redux in your React project. You guys can take a reference from to set up your modular Redux store.
  • Inside react-sortable-hoc, There are basically three basic components (SortableContainer, SortableElement) that are helping us achieve the drag & drop functionality. SortableContainer will act as a list container (Unordered List - <ul>) which will contain the list item as SortableElement wrapped around a list item. 
  • Let’s define some dummy data inside our root redux state as our initialState which is going to be used for the list item representation in a grid layout.

const initialState = {
  list: [
    {id: Math.random(), imgUrl: ""},

  • Create a new directory Container where we are going to create a new component AppContainer through which our redux state will be injected into the App Component.
  • Inject the data as

const mapStateToProps = (state) => {return {    data: state.list  }};
  • orderList Function as

const mapDispatchToProps = (dispatch, props) => ({
  orderList: ({oldIndex, newIndex}) => {
    dispatch(listActions.orderList(oldIndex, newIndex))
  • Now we have the data available in the App, we now need to render these items and I am using Bootstrap 4 to make the grid layout and it is pretty straightforward to implement

<SortableComponent data={this.props.list} onSortEnd={this.props.orderList}/>

Where the list is the data and orderList is a function, coming from the AppContainers followed by redux, will provide data and take care of the order of the list.


Let’s look at the summary of our implementation. The data is being fetched from the redux state along with a callback called orderList, which is injected into the App component through AppContainer. Finally, we have defined a template to be wrapped inside the SortableElement which would act as a Grid List Item. Sortable Component wrapper inside App component takes over to handle the drag and drop stuff. Now if you see the business logic to reorder and fetch the list is completely separated from the UI and reordering of the list is achieved with minimal efforts.

Complete code -


Written by
No art workers.
We'd love to talk about your business objectives