Skip to content

Remove unnecessary memoization from a code example #4803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

kopeczech
Copy link
Contributor


name: 📝 Documentation Fix
about: Removing unnecessary memoization from a code example as it might confuse people

What docs page needs to be fixed?

  • Section: Writing Memoized Selectors with Reselect
  • Page: Deriving Data with Selectors

What is the problem?

Using (createSelector) for the selectA1 selector directly contradicts the Balance Selector Usage section, which says in bold text the following: A selector function that does a direct lookup and return of a value should be a plain function, not memoized. Therefore this code example might confuse people about when to use memoization.

const state = {
  a: {
    first: 5
  },
  b: 10
}

const selectA = state => state.a
const selectB = state => state.b

const selectA1 = createSelector([selectA], a => a.first)

const selectResult = createSelector([selectA1, selectB], (a1, b) => {
  console.log('Output selector running')
  return a1 + b
})

const result = selectResult(state)
// Log: "Output selector running"
console.log(result)
// 15

const secondResult = selectResult(state)
// No log output
console.log(secondResult)
// 15

What changes does this PR make to fix the problem?

Not using createSelector for this one.

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

netlify bot commented Jul 22, 2025

Deploy Preview for redux-docs ready!

Name Link
🔨 Latest commit b5f94d3
🔍 Latest deploy log https://app.netlify.com/projects/redux-docs/deploys/687f90e3a7d0470008c7e086
😎 Deploy Preview https://deploy-preview-4803--redux-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@timdorr
Copy link
Member

timdorr commented Jul 23, 2025

Thanks!

@timdorr timdorr merged commit 44486e9 into reduxjs:master Jul 23, 2025
12 checks passed
@markerikson
Copy link
Contributor

Yeah, honestly we need a more realistic example here. Would appreciate a PR for that if you're interested!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants