Skip to content

Redux Essentials Tutorial Part 4 has a type error #3812

Closed
@samwightt

Description

@samwightt

What docs page needs to be fixed?

  • Updating Post Entries:
  • Redux Essentials, Part 4: Using Redux Data:

What is the problem?

On the Redux Essentials, Part 3: Basic Redux Data Flow page, the user is told to create this initial state containing integer ids:

const initialState = [
  { id: 1, title: 'First Post!', content: 'Hello!' },
  { id: 2, title: 'Second Post', content: 'More text' }
]

However, later on in the tutorial, the user is told to create a SinglePostPage that compares a route parameter (a string) with each post id. Because a triple equals sign is used and type conversion doesn't happen, the original data will always show the not found page. New data works just fine, but old data does not.

What should be changed to fix the problem?

The selector code should be:

const post = useSelector(state =>
    state.posts.find(post => post.id.toString() === postId)
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions