Bird
0
0

How can you combine multiple selectors to create a selector that returns the full name from separate first and last name selectors?

hard📝 component behavior Q9 of 15
Angular - State Management
How can you combine multiple selectors to create a selector that returns the full name from separate first and last name selectors?
const selectFirstName = (state) => state.firstName;
const selectLastName = (state) => state.lastName;
Aconst selectFullName = createSelector(selectFirstName, selectLastName, (first, last) => first + last);
Bconst selectFullName = createSelector(selectFirstName, selectLastName, (first, last) => `${first} ${last}`);
Cconst selectFullName = createSelector(state => state.firstName + state.lastName);
Dconst selectFullName = createSelector(selectFirstName, selectLastName, (first, last) => first.concat(last));
Step-by-Step Solution
Solution:
  1. Step 1: Use createSelector with multiple input selectors

    Pass both selectFirstName and selectLastName as inputs.
  2. Step 2: Combine inputs with template literal

    Use `${first} ${last}` to join names with space.
  3. Final Answer:

    const selectFullName = createSelector(selectFirstName, selectLastName, (first, last) => `${first} ${last}`); -> Option B
  4. Quick Check:

    Multiple selectors combined with template literal [OK]
Quick Trick: Combine selectors with createSelector and template literals [OK]
Common Mistakes:
  • Concatenating without space
  • Passing single function instead of multiple selectors
  • Using concat without space

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes