Using Algolia react-instantsearch with react-native

不羁的心 提交于 2019-12-14 03:57:50

问题


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,
    },
});

回答1:


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

Thanks!




回答2:


Try wrapping the TextInput in the SearchBox:

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


来源:https://stackoverflow.com/questions/41064940/using-algolia-react-instantsearch-with-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!