From 155d48ad1a05c103709a1477ee8f1453584f4883 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 29 Jul 2020 11:37:09 -0400 Subject: [PATCH] Fix #352. (#353) This fixes #352. The bug was indeed introduced by #346, which essentially split what was previously a single state update into two separate ones: this then caused render() to be called in a state where the was mounted and immediately unmounted. --- client/src/containers/AddressPage.tsx | 34 +++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/client/src/containers/AddressPage.tsx b/client/src/containers/AddressPage.tsx index e6df30bb6..b686528ef 100644 --- a/client/src/containers/AddressPage.tsx +++ b/client/src/containers/AddressPage.tsx @@ -105,38 +105,36 @@ export default class AddressPage extends Component { // Processes the results and setState accordingly. Doesn't care where results comes from handleResults = (results: SearchResults) => { const { geosearch, addrs } = results; + let userAddr: AddressRecord | undefined = undefined; if (!geosearch) { throw new Error("Address results do not contain geosearch results!"); } - this.setState({ - hasSearched: true, - geosearch: geosearch, - searchAddress: { ...this.state.searchAddress, bbl: geosearch.bbl }, - }); - /* Case for when our API call returns a portfolio of multiple associated addresses */ if (addrs.length) { - const userAddr = _find(addrs, { bbl: geosearch.bbl }); + userAddr = _find(addrs, { bbl: geosearch.bbl }); if (!userAddr) { throw new Error("The user's address was not found in the API Address Search results!"); } - - this.setState( - { - userAddr: userAddr, - assocAddrs: addrs, - }, - () => { - this.handleAddrChange(userAddr); - } - ); } + + this.setState( + { + hasSearched: true, + geosearch: geosearch, + userAddr, + assocAddrs: addrs, + searchAddress: { ...this.state.searchAddress, bbl: geosearch.bbl }, + }, + () => { + this.handleAddrChange(userAddr); + } + ); }; - handleAddrChange = (addr: AddressRecord) => { + handleAddrChange = (addr?: AddressRecord) => { this.setState({ detailAddr: addr, detailMobileSlide: true,