Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Error: "state.x is undefined" while calling nested memoized selectors #10

Closed
@markerikson

Description

@markerikson

I'm working on trying outproxy-memoize for the first time, and I'm using the Redux Fundamentals todo app example as the testbed.

I tried updating a couple of the selectors to usememoize(), including callingselectFilteredTodos fromselectFilteredTodoIds:

reduxjs/redux-fundamentals-example-app@f270ea1

exportconstselectFilteredTodos=memoize((state)=>{console.log('Original state: ',getUntrackedObject(state))const{ status, colors}=state.filtersconsttodos=selectTodos(state)constshowAllCompletions=status===StatusFilters.Allif(showAllCompletions&&colors.length===0){returntodos}constcompletedStatus=status===StatusFilters.Completed// Return either active or completed todos based on filterreturntodos.filter((todo)=>{conststatusMatches=showAllCompletions||todo.completed===completedStatusconstcolorMatches=colors.length===0||colors.includes(todo.color)returnstatusMatches&&colorMatches})})/*export const selectFilteredTodoIds = createSelector(  // Pass our other memoized selector as an input  selectFilteredTodos,  // And derive data in the output selector  (filteredTodos) => filteredTodos.map((todo) => todo.id))*/exportconstselectFilteredTodoIds=memoize((state)=>{returnselectFilteredTodos(state).map((todo)=>todo.id)})

However, this is throwing an exception when it tries to destructure fromstate.filters:

TypeError: Cannot destructure property 'status' of 'state.filters' as it is undefined.    at http://localhost:3000/static/js/main.chunk.js:1194:5    at http://localhost:3000/static/js/1.chunk.js:66229:17    at http://localhost:3000/static/js/main.chunk.js:1222:10    at Object.current (http://localhost:3000/static/js/1.chunk.js:66229:17)    at Subscription.checkForUpdates [as onStateChange] (http://localhost:3000/static/js/1.chunk.js:95055:47)

Ithink it's due to the use of nested selectors here. If I copy-paste the filtering logic over intoselectFilteredTodoIds and use that instead ofselectFilteredTodos(state), it runs fine.

So, my guess is that it has something to do with passing an already-wrappedstate value from one memoized selector into another selector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp