reactjs / reactjs/react.dev

[Tutorial] Potentially confusing explanation of how a component rendering is triggered

Open
#3,894 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

I'm new to React and when learning, I first went through the tutorial and then went through the docs. In the tutorial I didn't quite understand why we absolutely have to use the setState() method. But when going through the Using State Correctly and then the API docs for setState() I understood why. Then I went back to the tutorial to see why I couldn't get this from the tutorial. State is introduced in the Making an Interactive Component section.

I think it'd be better if it's explicitly mentioned here that state changes are what causes components to be re-rendered and hence, one shouldn't attempt to modify state directly. The following part particularly is what gave the wrong impression I think. I took this to mean that it's events such as onClick that triggers a rendering.

By calling this.setState from an onClick handler in the Square’s render method, we tell React to re-render that Square whenever its <button> is clicked.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the tutorial's Making an Interactive Component section alongside the linked Using State Correctly and setState() API documentation. Focus on the quoted explanation and verify that the revised text clearly distinguishes click events from state changes. Done means a newcomer understands why setState() triggers rendering and why state should not be modified directly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.