Get custom params in custom widget

Hello there !

I created a custom widget with instantsearch.js and places.js. I’d like to get custom params from the init method to the state, to improve my SEO. The first param of my url is the “what”, the second is the “where” you search.
The first works fine because i’m using the native search parameters “query”, but for the second i’d like a custom string, not avalaible in search parameters…

Checkout the code : https://codesandbox.io/s/instantsearch-places-urlsync-x-geo-5d751

From customPlaces.js, i’d like to get the name and postcode from the result (lines 23, 24), in getWidgetState, to set both in the uiState, (line 54).
My router works fine, as you can see string appears in url. If you proceed a request, everything seems fine, but take a look in the console (not the codesandboxe console, the browser’s), there is a 400 on the algolia request that say :

“1. message: “Unknown parameter: postcode””.
Indeed it does not know, it’s a custom one :smiley:

So question is : there is a clean solution to get custom params from the render to the getWidgetState on a custom widget ?

thanks a lot

I’m not sure if I fully understood what you want to do, but the pattern we use in our own widgets is storing it in a separate object:

const connector = () => {
  const widgetState = {};
  return {
    init() {
      widgetState.xxx = yyy
    },
    getWidgetState() {
      return { myKey: widgetState.xxx }
    }
  }
}

this is a simplified example, but hope it helps!