React-instantsearch: `connectRange` connector always provides `undefined` for min and max value

Created on 13 Oct 2019  路  3Comments  路  Source: algolia/react-instantsearch

Describe the bug 馃悰

I am using connectRange connector to display slider in React Native but it provides min and max value undefined in every render

Output in dev console

{
  ...otherFields,
  min: undefined,
  max: undefined,
  currentRefinment: {
    min: undefined,
    max: undefined,
  }
}

To Reproduce 馃攳

Due to project begin private i can't share the whole repo:
but here is the main file:

...otherImports
import { Configure, InstantSearch } from "react-instantsearch-native"

import {
  connectInfiniteHits,
  connectRange,
  connectSearchBox,
} from "react-instantsearch/connectors"

import ResultsComponent from './ResultsComponent'

class Products extends Component<Props, {}> {
  render() {
    return (
      <Block flex={1} color="gray3">
        <InstantSearch
          appId="[APP_ID]"
          apiKey="[API_KEY]"
          indexName="[INDEX_NAME]"
          initialParams={{ filters: "category:jordan" }}
        >
          <RangeInput attribute="price" />
          <Results />
        </InstantSearch>
      </Block>
    )
  }
}

const RangeInput = connectRange(props => {
  console.log(props)

  return <Text>I am from Range!</Text>
})

const Results = connectInfiniteHits(ResultsComponent)

export default Products

Expected behavior 馃挱

Expected to see
Either

{
  ...otherFields,
  min: 1000, // or min value according to filter query
  max: 5000, // or max value according to filter query
  currentRefinment: {
    min: undefined,
    max: undefined,
  }
}

Or

{
  ...otherFields,
  min: undefined,
  max: undefined,
  currentRefinment: {
    min: 5000, // or min value according to filter query
    max: 1000, // or max value according to filter query
  }
}

Screenshots 馃枼

gg

Environment:

  • OS: Linux(Ubuntu 19.04) with physical Android 8.0 device
  • Browser: Chrome, React Native Debugger
  • Version react-instasearch 5.7.0

Additional context

I tried using componentWillReceiveProps but not working

componentWillReceiveProps(nextProps) {
  if (nextProps.canRefine) {
    this.setState({
      min: nextProps.currentRefinement.min,
      max: nextProps.currentRefinement.max,
    })
  }
}

All 3 comments

Hi @developerk786, is the attribute price you're using set up as an attributeForFaceting in the index settings (dashboard)?

Thanks, @Haroenv mate i totally forgot about that, now its working as expected!

This is a good reminder for us to give errors or warning messages when incompatible settings are set.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markmiller21 picture markmiller21  路  3Comments

rtman picture rtman  路  5Comments

flouc001 picture flouc001  路  5Comments

aaronbushnell picture aaronbushnell  路  4Comments

oznekenzo picture oznekenzo  路  3Comments