Websites v4 docs v5.2.5
    Preparing search index...

    Function useGenerateSearchFromProperty

    • Hook to be called on the property show page which builds a search from the current property and adds to the search history to the search_history indexedDB store if no history is already present. This search is subsequently used to build the url for the BackToSearchLink.

      Due to the async behaviour of indexedDB transactions, the useEffect in the BackToSearchLink runs before the addToStore has completed and so finds no search history and does not set the correct search url.

      Calling the functionality to generate the search from the property from inside the BackToSearchLink results in multiple duplicate searches being added to the search_history store if more than one BackToSearchLink included on the property show.

      In order to circumvent this, the useGenerateSearchFromProperty hook sets the initialSearch redux state after adding the search to the indexedDB store. This in turn reruns the useEffect in the BackToSearchLink which can then successfully set the correct search url.

      Parameters

      • __namedParameters: { agency: any; property: any }

      Returns void

      // In property show page

      useGenerateSearchFromProperty();