From the course: React.js: Building an Interface

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Setting up a sort

Setting up a sort - React.js Tutorial

From the course: React.js: Building an Interface

Start my 1-month free trial

Setting up a sort

- [Instructor] It's time to add sorting to our application. In this video, I'm going to show you how to actually create the sorting algorithm and then in the next video, I'll show you how to program this interface right here. So I'm going to get started by working with the App.js module and I'm going to need a couple of other states. So we'll create a sortBy state and of course, we'll need a setSortBy method up here. This is going to once again useState and I'm going to initialize that by petName. So by default, it's going to sort things by petName. Next, I'm going to create an orderBy state and then I'll create a setOrderBy method right here and then this will be initialized to ascending, so ascending order. All right, let's go ahead and create our sorting algorithm. So in the same place that we filter the appointments, I'm going to add an additional section here and use the JavaScript sort function. So JavaScript sort…

Contents