Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Displaying Number of Posts and Users | Creating a React-Redux Application
Introduction to Redux
course content

Зміст курсу

Introduction to Redux

Displaying Number of Posts and Users

We also want to display the number of posts created by a user and the number of posts in general. Apart from that, we also want to show the number of users.

For that, we need to create another selector in the posts slice, which selects posts based on author. Normally selectors cannot take in arguments; however, using the following syntax, we can make a selector which takes in an argument:

We also need to keep track of all the users/authors, and for that, we will need to create a new empty array for storing all the authors and updating the list whenever a new author creates a post. By now, the code should look something like this.

Now that we have the relevant selectors, we can import them into index.js and display the data!

In the ProfileDetails, we can use the selector like this:

The retrieved data can then be displayed accordingly:

Similarly, we can select total posts and authors, and display them in the AppDetails component. The final code for both components should look something like this.

Following is a sandboxed version of the application:

Which of the following is the correct way to pass an argument into a selector function?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 4. Розділ 7
We're sorry to hear that something went wrong. What happened?
some-alt