question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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).

https://github.com/facebook/react/blob/aeda7b745d9c080150704feb20ea576238a1b9a1/packages/react/src/ReactBaseClasses.js#L45-L47

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, Aug 21, 2018

You’re not looking at the right implementation. This is a shim.

The right one is here.

If you’d like to propose a change to the React API to include this, please do it here: https://github.com/reactjs/rfcs

Feel free to send a PR that removes the comment. The comment seems wrong.

0reactions
meszaros-lajos-gyorgycommented, Aug 21, 2018

Thanks for the information!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React setState callback not called for external (npm packaged ...
One thing I found interesting is that this is happening for a component I am using via an npm package. In my own...
Read more >
React interactivity: Events and state - Learn web development
Once we have our callback prop, we can call it inside <Form /> to send the right data to <App /> . Handling...
Read more >
What is the purpose of callback function as an argument of ...
The callback function is invoked when setState finished and the component gets rendered. Since setState() is asynchronous the callback function is used for ......
Read more >
React's setState is a special function, and it helps with ...
setState() wouldn't work because there is no component on which to set. ... trick here is that setState accepts a second parameter which...
Read more >
Dive into React codebase: Handling state changes
Bam. This code doesn't work. Why is so? This is because setState works in an asynchronous way. That means after calling setState ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found