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

4.5.1 - Objects are not valid as a React child #1115

Closed
deftomat opened this issue Dec 4, 2018 · 3 comments
Closed

4.5.1 - Objects are not valid as a React child #1115

deftomat opened this issue Dec 4, 2018 · 3 comments

Comments

@deftomat
Copy link

deftomat commented Dec 4, 2018

Description

We have the following component:

export default function Component({ visible }) {
  if (!visible) return null;
  return <div>some content</div>;
}

Initially, when you arrive on a page, visible is false. So, component will render nothing.
Later, when visible change to true, some content should be rendered.

Expected behavior

Should show/hide content based on props.

Actual behavior

Changing visible to TRUE throws the following error:

Error: Objects are not valid as a React child (found: object with keys {props, context, refs, updater, __reactstandin__proxyGeneration, __reactstandin__cachedResult}). If you meant to render a collection of children, use an array instead.

Possible workarounds:

  • Replace if (!visible) return null with if (!visible) return <div />
  • downgrade to 4.3.*

Environment

React Hot Loader version: 4.5.1
React version: 16.6.3
React DOM version: 16.6.3

@theKashey
Copy link
Collaborator

This is 4.5.0 change.

By default configuration, SFCs are wrapped by a complex thing, which returns a class instance from SFC call(it's a long story). This "conversion" could be done only once, during the first component render. Later would lead to an error.

4.5.0 adds "early reject" if render return null. And later returns class wrapper, when it's already too late.

For now, you can solve this by setting pureSFC configuration option. See readme for details.

@theKashey
Copy link
Collaborator

Should be fixed in 4.5.2

@deftomat
Copy link
Author

deftomat commented Dec 7, 2018

Thanks! Looks like it works.

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