codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

The True Delight of React’s Error and Warning Messages

Omar Alshaker
codeburst
Published in
5 min readJan 13, 2018

--

Photo by Austin Chan on Unsplash

Introduction

React

TypeError: undefined is not an object

1. A simple one

Warning: MyComponent(…): No `render` method found on the returned component instance: you may have forgotten to define `render`.

2. A trickier one

Warning: MyComponent has a method called componentDidUnmount(). But there is no such lifecycle method. Did you mean componentWillUnmount()?

3. A little obvious one

Warning: Cannot update during an existing state transition (such as within `render` or another component’s constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to `componentWillMount`.

4. Not quite obvious

Warning: setState(…): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.Please check the code for the MyComponent component.

5. Pure elegance

Warning: Received `true` for non-boolean attribute `type`. If this is expected, cast the value to a string.
in input

6. The beginner’s rescuer

Warning: <greetingComponent /> is using uppercase HTML. Always use lowercase HTML tags in React.Warning: The tag <greetingComponent> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.

7. OK I fixed it, but it still doesn’t work

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
ReactDOM.render(<GreetingComponent />, document.getElementById(“root”));

8. A very common mistake in the first couple days

Warning: Invalid DOM property `class`. Did you mean `className`?
in h1 (created by GreetingComponent)
in GreetingComponent

9. Why don’t you come back? 🎼

Uncaught Error: GreetingComponent(…): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

10. And the one that doesn’t need an example:

You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

--

--

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Responses (1)