将 Algolia react-instantsearch 与 react-native 结合使用

IT技术 reactjs react-native algolia react-instantsearch
2021-05-07 02:26:36

我正在尝试使用 react-native获取新的 Algolia react- instantsearch组件。

我一直在遵循指南,但我完全被卡住了。

基本上,每当我尝试将我的<SearchBox />组件添加<InstantSearch />组件中时,我的应用程序都会以预期的组件类结束,得到 [object Object]

据我所知,我正在连接<SearchBox />connectSearchBox连接器,所以我不确定发生了什么。

代码(我确实有 appId、apiKey 和索引的实际值):

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,
    },
});
2个回答

尝试将 TextInput 包装在 SearchBox 中:

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