Skip to content

enqueueCallback invariant should specify/identify actual object in failure message #5172

@blainekasten

Description

@blainekasten

Oddly enough, the two examples below are not equal as I thought they would be.

window.addEventListener(
  'resize',
  this.forceUpdate.bind(this)
);
// throws error

window.addEventListener(
  'resize',
  () => this.forceUpdate()
);
// works fine

The error is as follows:

Error: Invariant Violation: enqueueCallback(...): You called `setProps`, `replaceProps`, `setState`, `replaceState`, or `forceUpdate` with a callback that isn't callable.

I'm assuming that is because the function as assuming an optional callback. But I would expect your code to do a typeof check, and not just a defined check. Can we change it to do a typeof fn === 'function' check? I can submit a PR.

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