diff --git a/hooks/src/index.js b/hooks/src/index.js index 847f40526f..4f208dab84 100644 --- a/hooks/src/index.js +++ b/hooks/src/index.js @@ -216,7 +216,7 @@ export function useReducer(reducer, initialState, init) { } }); - return shouldUpdate + return shouldUpdate || hookState._internal.props !== p ? prevScu ? prevScu.call(this, p, s, c) : true diff --git a/hooks/test/browser/useState.test.js b/hooks/test/browser/useState.test.js index 64b5e59af8..58b152afc8 100644 --- a/hooks/test/browser/useState.test.js +++ b/hooks/test/browser/useState.test.js @@ -346,4 +346,29 @@ describe('useState', () => { expect(renderSpy).to.be.calledTwice; }); + + // see preactjs/preact#3731 + it('respects updates initiated from the parent', () => { + let setChild, setParent; + const Child = props => { + const [, setState] = useState(false); + setChild = setState; + return

{props.text}

; + }; + + const Parent = () => { + const [state, setState] = useState('hello world'); + setParent = setState; + return ; + }; + + render(, scratch); + expect(scratch.innerHTML).to.equal('

hello world

'); + + setParent('hello world!!!'); + setChild(true); + setChild(false); + rerender(); + expect(scratch.innerHTML).to.equal('

hello world!!!

'); + }); });