8000 Introduction To State: Error on What is state in React example · Issue #29404 · TheOdinProject/curriculum · GitHub
[go: up one dir, main page]

Skip to content
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

Introduction To State: Error on What is state in React example #29404

Open
3 tasks done
moledomario opened this issue Feb 12, 2025 · 1 comment
Open
3 tasks done

Introduction To State: Error on What is state in React example #29404

moledomario opened this issue Feb 12, 2025 · 1 comment

Comments

@moledomario
Copy link

Checks

Describe your suggestion

"onClick={onClick(color)}" generates a infinite loop, you need to add an anonimus function, "onClick={() => onClick(color)}"

Path

Foundations, Node / JS

Lesson Url

https://www.theodinproject.com/lessons/node-path-react-new-introduction-to-state

(Optional) Discord Name

No response

(Optional) Additional Comments

No response

@JoshDevHub
Copy link
Contributor

@moledomario The code in the codesandbox doesn't infinite loop for me. Are you sure you've written the onClick() function such that it returns a function?

// this works
const onClick = (color) => () => {
  setBackgroundColor(color)
}

// this wouldn't
const onClick = (color) => {
  setBackgroundColor(color)
}

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

No branches or pull requests

2 participants
0