Skip to content

Component.prototype.setState() callback is not receiving any arguments #13452

@meszaros-lajos-gyorgy

Description

@meszaros-lajos-gyorgy

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Component.prototype.setState()'s callback is not receiving any parameters, though line 47 in /packages/react/src/ReactBaseClasses.js states, that: It will be called with the up to date component arguments (state, props, context).

* When a function is provided to setState, it will be called at some point in
* the future (not synchronously). It will be called with the up to date
* component arguments (state, props, context). These values can be different

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

https://jsfiddle.net/n5u2wwjg/145295/

Please check the console after clicking the button, as it will display an empty array, indicating that it doesn't get called with any parameters.

What is the expected behavior?

As the comment mentions, we should get the updated state and props and context as arguments.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

I'm checking this behaviour in React v16.4.2 using Chrome 68, Mac OS High Sierra 10.13.6 and it also didn't seem to work in previous versions, though I didn't go back in the version history.

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