reactjsreact-nativealgoliareact-instantsearch

Using Algolia react-instantsearch with react-native


I'm trying to get the new Algolia react-instantsearch component using react-native.

I've been following the guide and I'm completely stuck.

Basically, anytime I try to add my <SearchBox /> component inside the <InstantSearch /> component, my app dies with a Expected a component class, got [object Object].

As far as I can tell, I'm wiring up <SearchBox /> to the connectSearchBox connector so I'm not sure what's going on.

Code (I do have real values for appId, apiKey, & index):

import React, {Component} from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ListView,
  TextInput,
  Image,
} from 'react-native';
import {InstantSearch} from 'react-instantsearch/native';
import {connectSearchBox} from 'react-instantsearch/connectors';
import * as Styles from '../../styles/';

const SearchBox = connectSearchBox(({currentRefinement, refine}) =>
  <TextInput
    style={{height: 40, borderColor: 'gray', borderWidth: 1}}
    onChangeText={(text) => refine(text)}
    value={currentRefinement}
  />);

export default class InfiniteSearch extends Component {
  constructor(props) {
    super(props);
  }

    render() {
        return (
            <View style={styles.container}>
              <InstantSearch
                className="container-fluid"
                appId="appId"
                apiKey="apiKey"
                indexName="indexName"
              >
                <SearchBox />
              </InstantSearch>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
      padding: 10,
    },
});

Solution

  • this is now solved in 2.0.1: https://github.com/algolia/instantsearch.js/blob/e15d37362fcd1eb60b5476307160062321983f09/CHANGELOG.md#201-2016-12-15

    Thanks!