From the course: Testing in React with Vitest
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Testing Redux Toolkit state - React.js Tutorial
From the course: Testing in React with Vitest
Testing Redux Toolkit state
- [Instructor] Continuing where we left off, we can begin migrating our application to use our configured reducers. Let's open our fruit search component and import our dependencies. I have the dependencies copied on my clipboard, but you can find the code that we are using at the end of this chapter, chapter 4.2-start. That is the branch where you'll find our code. After importing our dependencies, we can then remove two states, set fruit and error state. After removing our two states, we will add our dispatch function call of type AppDispatch from React Redux, which dispatches a function call. Then add our fruit status and error selectors, which will take the root state from our state.fruits global state, and will return the fruit status and error respectively. Super. Let's declutter our use effect. Where we will dispatch our fetch fruit, call if there is a fruit name. On our return, our input doesn't change. However, if our status is loading, we add a card with a block of loading…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.