Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Selectors | Fundamental Concepts
Introduction to Redux

book
Selectors

Selectors are custom functions that extract specific values or pieces of information from a store's state value. As the state value grows and size and complexity, the selector functions can be useful in extracting relevant information.

A simple example is as follows:

js
// Consider that state has a dictionary of posts identified by ids, and each post object has a 'date' key
// We create a selector called 'selectPostDate', which extracts the post date based on 'id'

let selectPostDate = (state, id) => state.posts[id].date;

const postDate = selectPostDate(store.getState());
console.log(postDate);
// 6 Nov 2023
question mark

Why are selectors useful?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 2. Capitolo 5

Chieda ad AI

expand
ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

We use cookies to make your experience better!
some-alt