diff --git a/hooks/src/index.js b/hooks/src/index.js index 9d2c3b2997..d838d17356 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -181,10 +181,10 @@ export function useReducer(reducer, initialState, init) { hookState._component = currentComponent; - if (!hookState._component._hasScuFromHooks) { - hookState._component.__hooks._hasScuFromHooks = true; - const prevScu = hookState._component.shouldComponentUpdate; - hookState._component.shouldComponentUpdate = (p, s, c) => { + if (!currentComponent._hasScuFromHooks) { + currentComponent._hasScuFromHooks = true; + const prevScu = currentComponent.shouldComponentUpdate; + currentComponent.shouldComponentUpdate = (p, s, c) => { if (!hookState._component.__hooks) return true; const stateHooks = hookState._component.__hooks._list.filter( x => x._component diff --git a/hooks/test/browser/useState.test.js b/hooks/test/browser/useState.test.js index c365af4fda..a79deef683 100644 --- a/hooks/test/browser/useState.test.js +++ b/hooks/test/browser/useState.test.js @@ -234,6 +234,32 @@ describe('useState', () => { expect(scratch.textContent).to.equal('hi'); }); + // https://github.com/preactjs/preact/issues/3669 + it('correctly updates with multiple state updates', () => { + let simulateClick; + function TestWidget() { + const [saved, setSaved] = useState(false); + const [, setSaving] = useState(false); + + simulateClick = () => { + setSaving(true); + setSaved(true); + setSaving(false); + }; + + return