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

Kursinnhold

Introduction to Redux

Introduction to Redux

1. Getting Started
2. Fundamental Concepts
3. Redux in Practice
4. Creating a React-Redux Application

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:

// 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

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

Introduction to Redux

Introduction to Redux

1. Getting Started
2. Fundamental Concepts
3. Redux in Practice
4. Creating a React-Redux Application

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:

// 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

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 2. Kapittel 5
some-alt