ReSub v2 setState not working?
See original GitHub issueHey you all - I’m testing out the 2.0.0-rc.1 and vs 1.2.2 I have a component that fails to setState correctly.
private _onNextPage = () => {
console.log(
'TIPI::_onNextPage - was on page ' + this.state.pageIndex + ' (max is ' + this.MAX_PAGE + ')'
);
let nextIndex = this.state.pageIndex + 1;
this.setState({ pageIndex: nextIndex >= this.MAX_PAGE ? this.MAX_PAGE : nextIndex });
console.log('TIPI::_onNextPage - will be on page ' + this.state.pageIndex);
};
It’s a simple pager, and I get ‘will be on page 0’ (the initial state) every click with 2.0.0-rc.1 but it increments nicely with 1.2.2.
That’s a vague report in and of itself but it is a clear regression with this code between those two versions.
I’m trying to get a repro together but in the meantime I also see this on an npm test
execution
mike@isabela:~/work/react-random/resub (master) % npm test
> resub@2.0.0-rc.1 test /home/mike/work/react-random/resub
> run-s clean:* karma:single-run
> resub@2.0.0-rc.1 clean:dist /home/mike/work/react-random/resub
> rimraf dist*
> resub@2.0.0-rc.1 karma:single-run /home/mike/work/react-random/resub
> karma start --singleRun
Starting type checking service...
Using 1 worker with 2048MB memory limit
Type checking in progress...
ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...
ERROR in /home/mike/work/react-random/resub/test/AutoSubscribe.spec.tsx(128,7):
TS2417: Class static side 'typeof OverriddenComponent' incorrectly extends base class static side 'typeof SimpleComponent'.
Types of property 'getDerivedStateFromProps' are incompatible.
Type 'GetDerivedStateFromProps<SimpleProps, SimpleState>' is not assignable to type 'GetDerivedStateFromProps<unknown, unknown>'.
Types of parameters 'nextProps' and 'nextProps' are incompatible.
Property 'ids' is missing in type 'Readonly<unknown>' but required in type 'Readonly<SimpleProps>'.
Version: typescript 3.5.3
Time: 2315ms
ℹ 「wdm」: Compiled successfully.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (11 by maintainers)
Top Results From Across the Web
React setState not updating properly - Stack Overflow
Your issue is handleTap . React state updates are asynchronous and "collated", meaning, calling setState several times within a single ...
Read more >resub - npm
A library for writing React components that automatically manage subscriptions to data sources simply by accessing them.
Read more >Why does setState() not work in my React app? - Medium
setState() internally works by merging the object passed to it to the current state. setState() takes an object as a parameter and merges...
Read more >Why my setState doesn't work? - Sergey Stadnik
It is almost as it doesn't work. The problem may go like this: You set a state with a setState. this.setState({count: 1}).
Read more >victorious titan's armor set
Throughout the limited time of the annual Solstice event in Destiny 2, Guardians can work to fully upgrade their set of Candescent armor...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As part of this v2 moveover, we’re continuing to try to simplify the happy path, and make it harder to hose yourself. So it’s still really good for us to flesh out cases like this, and see how we can add more exceptions/checking to help people down the happy path.
echoing that, my main takeaway is that I was dealing with state terribly (in my subjective opinion), so in that way the v1->v2 behavior change has been quite illuminating and resulted in a big project improvement.
Also I took a quick stab at a reproduction starting with the very code I saw it in and I must retract my assertion that the new 3rd argument was not updated. I can no longer reproduce it. I assume it was still a reference to this.state.<var> vs state.<var>.
So I return to my previous assertion that with 2.0.0-rc.2 (and my state-handling reorganization) my project is working fine.