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

"Rules of React" docs would cause TypeError #6903

Open
reko-aviary opened this issue May 23, 2024 · 8 comments · May be fixed by #6905
Open

"Rules of React" docs would cause TypeError #6903

reko-aviary opened this issue May 23, 2024 · 8 comments · May be fixed by #6905

Comments

@reko-aviary
Copy link

The example here would cause a TypeError: Assignment to constant variable.

function Counter() {
const [count, setCount] = useState(0);
function handleClick() {
count = count + 1; // 🔴 Bad: never mutate state directly
}

reko-aviary added a commit to reko-aviary/react.dev that referenced this issue May 23, 2024
@ijayhub
Copy link

ijayhub commented May 25, 2024

is it still valid... can i work on this?

@reko-aviary
Copy link
Author

reko-aviary commented May 27, 2024

is it still valid... can i work on this?

There's already a PR for this #6905

@ijayhub
Copy link

ijayhub commented May 27, 2024 via email

@imparth7
Copy link
Contributor

imparth7 commented Sep 9, 2024

If this issue was solved then close this issue.

@reko-aviary
Copy link
Author

The PR was not merged by the core team, so will rather keep this open. It should be automatically closed when the pull request is.

@imparth7
Copy link
Contributor

Can you tell me what the actual issue in this code? because I show there is no issue. ( Tell me how you get this issue. )

I found that code on the page and this code is written for the what kind of mistake cannot do in react state (Don’t mutate State
).

@reko-aviary
Copy link
Author

const [foo, bar] = [1, 2];
foo = foo + 1;
// Uncaught TypeError: Assignment to constant variable.

@TUNISIA-user
Copy link

const Counter =()=> {
const [count, setCount] = useState(0);

const handleClick =()=> setCount((prev)=>prev+1)

}

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 a pull request may close this issue.

4 participants