Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

React 16 "Expected onClick listener to be a function, instead got a value of boolean type" #94

Closed
steveliles opened this issue Sep 18, 2017 · 18 comments

Comments

@steveliles
Copy link

steveliles commented Sep 18, 2017

I just updated to React 16 and now I'm seeing lots of warnings from react-json-tree (via redux-log-monitor):

warning.js:35 Warning: Expected `onClick` listener to be a function, instead got a value of `boolean` type.
    in span (created by JSONNestedNode)
    in li (created by JSONNestedNode)
    in JSONNestedNode (created by JSONObjectNode)
    in JSONObjectNode (created by JSONNode)
    in JSONNode (created by JSONNestedNode)
    in ul (created by JSONNestedNode)
    in li (created by JSONNestedNode)
    in JSONNestedNode (created by JSONObjectNode)
    in JSONObjectNode (created by JSONNode)
    in JSONNode (created by JSONTree)
    in ul (created by JSONTree)
    in JSONTree (created by LogMonitorEntry)
    in div (created by LogMonitorEntry)
    in div (created by LogMonitorEntry)
    in LogMonitorEntry (created by LogMonitorEntryList)
    in div (created by LogMonitorEntryList)
    in LogMonitorEntryList (created by LogMonitor)
    in div (created by LogMonitor)
    in div (created by LogMonitor)
    in LogMonitor (at ReduxDevTools.js:13)`

I believe this is due to the DOM attribute changes in React 16, specifically the "Non-boolean attributes with boolean values" described here - https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html.

And in react-json-tree the culprit is src/JSONNestedNode.js:

        <span
          {...styling('nestedNodeItemString', ...stylingArgs)}
          onClick={expandable && this.handleClick}
        >

Where {expandable && this.handleClick} will evaluate to false if expandable is false.

steveliles added a commit to steveliles/react-json-tree that referenced this issue Sep 18, 2017
…unction or undefined for the onclick handler, instead of function or boolean, as react 16 warns about booleans
@GuillaumeCisco
Copy link
Contributor

Just created a PR for fixing this issue here : #97

redux-devtools-log-monitor depends of it.
Should be great to deploy it as soon as possible.

@danbovey
Copy link

There was already a PR open for this #95

But I like @GuillaumeCisco solution better, it makes sense to put the if in the handleClick function.

jthetzel added a commit to jthetzel/react-live that referenced this issue Sep 28, 2017
React 16 warns and ignores boolean values in non-boolean
attributes. React 15 converted these to strings and passed
through. Replacing logical operators with ternary in attributes
removes the warning.

alexkuz/react-json-tree#94
https://facebook.github.io/react/blog/2017/09/08/dom-attributes-in-react-16.html
@GuillaumeCisco
Copy link
Contributor

Can we merge it, so?

@arman-mukatov
Copy link

what in the end decided? I get the same warning..

@GuillaumeCisco
Copy link
Contributor

@arman-mukatov With which code?

@rsolomon
Copy link

@alexkuz any chance you can merge and release this?

@rsolomon
Copy link

rsolomon commented Oct 10, 2017

Heads up for anyone else blocked by this: I released a forked version of this package with the React 16 fix under @rsolomon/react-json-tree@0.10.10 via https://github.com/rsolomon/react-json-tree

Feel free to submit PRs there as well, until we get confirmation that this repository is still maintained.

@alexkuz
Copy link
Owner

alexkuz commented Oct 11, 2017

I'll try to review this and other PRs this weekend.
BTW if anyone is willing to maintain this repo (as I'm obviously failing to do this lately), please let me know.
Thanks, everyone!

vartija added a commit to Opetushallitus/henkilo-ui that referenced this issue Oct 12, 2017
@GuillaumeCisco
Copy link
Contributor

Can we have some hope of a merge here followed by a release?

@MrSauceman
Copy link

Yes, please release this. This error spams my console over and over to the point that I had to disable DevTools.

@sovanna
Copy link

sovanna commented Oct 29, 2017

going to disable devTools too, waiting the release

@alexkuz
Copy link
Owner

alexkuz commented Oct 29, 2017

Published in v0.11.0, sorry it took so long.

@alexkuz alexkuz closed this as completed Oct 29, 2017
@foxhound87
Copy link

foxhound87 commented Nov 16, 2017

Sorry @alexkuz , I'm still getting Warning: Expected onClick listener to be a function, instead got false.

Warning: Expected `onClick` listener to be a function, instead got `false`.

If you used to conditionally omit it with onClick={condition && value}, pass onClick={condition ? value : undefined} instead.
    in label (created by JSONNestedNode)
    in li (created by JSONNestedNode)
    in JSONNestedNode (created by JSONArrayNode)
    in JSONArrayNode (created by JSONNode)
    in JSONNode (created by JSONNestedNode)
    in ul (created by JSONNestedNode)
    in li (created by JSONNestedNode)
    in JSONNestedNode (created by JSONObjectNode)
    in JSONObjectNode (created by JSONNode)
    in JSONNode (created by JSONNestedNode)
    in ul (created by JSONNestedNode)
    in li (created by JSONNestedNode)
    in JSONNestedNode (created by JSONObjectNode)
    in JSONObjectNode (created by JSONNode)
    in JSONNode (created by JSONTree)
    in ul (created by JSONTree)
    in JSONTree (created by _class)

@GuillaumeCisco
Copy link
Contributor

@foxhound87, the issue is now in the redux devtools repo, please upvote it

@foxhound87
Copy link

@GuillaumeCisco I'm not using redux devtools

@GuillaumeCisco
Copy link
Contributor

@foxhound87 So there is surely another part of the code that do this.
Can you try to spot it using breakpoints?
Or maybe you can share a project that highlights this behavior.

@foxhound87
Copy link

I’m using the package in this project:
https://github.com/foxhound87/mobx-react-form-demo

@foxhound87
Copy link

UP

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants