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

[BUGFIX] Objects are not valid as a React child (found object with keys {children} ) **Runtime Error** #4

Merged

Conversation

gaabgonca
Copy link

Problem
When introducing children to DatePicker, Next.js throws the following runtime error

children-bug

How to reproduce

  • Run the demo app provided in this repository
  • Update pages>index.tsx so that the DatePicker component is not self-closing but has children
  • A simple <div/> is sufficient to get the bug. Like this:
<DatePicker show={show} setShow={(state) => setShow(state)} options={options} classNames="absolute" >
	<div/>
</DatePicker>

Root cause
The ReactNode as the type of children prop was too broad. This caused children to be identified as an object/ any type making React unable to render it. This was fixed in React 18.

Solution
Narrow down the type of children to ReactElement and destructure it when used.

Extra
Code provided in README.md was missing parenthesis on useState<boolean>(false) call, thus disabling blind copy-pasting. That was fixed too.

Changes made

  • Update usages of ReactNode with ReactElement
  • Add missing parenthesis on README.md
  • Update DatePicker children rendering logic

- Add missing parenthesis on README.md
- Update DatePicker children rendering logic
@gaabgonca gaabgonca changed the title [BUGFIX] Objects are not valid as a React child (found object with keys {children} ) [BUGFIX] Objects are not valid as a React child (found object with keys {children} ) **Runtime Error** Jan 30, 2023
@OMikkel OMikkel merged commit 11303cd into OMikkel:master Feb 27, 2023
@OMikkel
Copy link
Owner

OMikkel commented Feb 27, 2023

This PR has been merged 😃

@diecodev
Copy link

diecodev commented Apr 6, 2023

This bug is still happen. Pls Fix it.

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 this pull request may close these issues.

3 participants