'NGRX selector : x is not a function
I'm curious to know why this raises a typerror is there something I'm missing?
export const selectAllUsers = createFeatureSelector<ReadonlyArray<User>>('users');
export const selectUser = () =>
createSelector(selectAllUsers, (users) => {
return users.find(
(user) =>
user.name === "Mr.Doe"
)});
Which is very similar to the Book example in the ngrx walktrhough will raise this error in the browser console :
ERROR TypeError: users.find is not a function
selectUser user.selector.ts:13
memoizedProjector ngrx-store.mjs:697
I will be able to get my user using the selectUser but that boggles me to see this error, I feel like I'm missing something important in typescript or in store selectors
Tested on firefox and chrome, both under linux
package.json
"@angular/animations": "~13.1.2",
"@angular/cdk": "^13.1.2",
"@angular/common": "~13.1.2",
"@angular/compiler": "~13.1.2",
"@angular/core": "~13.1.2",
"@angular/forms": "~13.1.2",
"@angular/material": "^13.1.2",
"@angular/platform-browser": "~13.1.2",
"@angular/platform-browser-dynamic": "~13.1.2",
"@angular/router": "~13.1.2",
"@ngrx/store": "^13.0.2",
"@ngrx/store-devtools": "^13.0.2",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.11.4"`
Edit 1: ERROR TypeError: user.find -> users.find
Edit 2: Nothing but users(players) in the user state, here is a screen taken from devtools, the names are different, hence the typo above
Solution 1:[1]
@Osakr, @mak15 and @MarteenDev were on the right path : the user state wasn't a pure array of players
Angular NGRX getting error when dispatching to state
I left a reducer that was polluting the state ( I didn't normalize my state at some point) Don't know why it was working tho, I may have not typed the reducer enough.
This is a first project so I didnt thoroughly did that
https://duncanhunter.gitbook.io/angular-and-ngrx/15.-strongly-type-our-store#2.-add-a-global-state-interface
Anyhow thanks for the help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
