Skip to content

new react apps state is undefined on class based component without a constructor #10598

@jlbaker99

Description

@jlbaker99

Describe the bug

Using state on a class based component without a constructor and creating methods will not compile because they are undefined. Using the EXACT same code in a react app I created over the weekend, it compiles and runs fine. Trying to create a new react app via 'npx create-react-app ' will not compile.

Did you try recovering your dependencies?

Yes I tried removing node_modules and creating new react apps via 'npx create-react-app test' numerous times

Which terms did you search for in User Guide?

State undefined class based component

Environment

It was not copies to my clipboard directly so heres my copy paste:
Environment Info:

current version of create-react-app: 4.0.3
running from /Users/joseph/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

System:
OS: macOS 11.1
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
Yarn: Not Found
npm: 7.5.6 - ~/.nvm/versions/node/v14.15.4/bin/npm
Browsers:
Chrome: 88.0.4324.192
Edge: Not Found
Firefox: 85.0.2
Safari: 14.0.2
npmPackages:
react: ^17.0.1 => 17.0.1
react-dom: ^17.0.1 => 17.0.1
react-scripts: 4.0.3 => 4.0.3
npmGlobalPackages:
create-react-app: Not Found

Steps to reproduce

(Write your steps here:)

  1. npx create-react-app test
  2. create a class based component
  3. initialize state without the use of a constructor or write an arrow function.

Expected behavior

State would be initialized and my app would compile

Actual behavior

state is undefined. method is undefined.
screenshot

Reproducible demo

I do not have the time at the moment to upload a link to a project. I will try to get a repo up soon if you need

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions