我试图从ReactiveBase有条件地渲染我的 Results 组件,但是每次我尝试使用三元运算符时,它都会破坏渲染。如果我删除三元,结果显示。
我正在使用该<ReactiveList>
组件在我的结果组件中显示结果。
我只想在用户实际提交搜索查询时显示结果。那么,如何在用户提交查询后才从内部有条件地呈现结果组件
到目前为止,这是我的代码:
import React, { Component } from 'react';
import { Redirect, withRouter } from 'react-router-dom';
import { ReactiveBase, DataSearch } from '@appbaseio/reactivesearch';
import Results from '../../components/appbaseio-search/Results';
class SearchContainer extends Component {
constructor(props) {
super(props);
this.state = {
redirect: false,
loading: false,
};
}
render() {
const { pathname } = this.props;
const { value, loading } = this.state;
const { redirect } = this.state;
if (redirect ) {
return (
<Redirect
to={{
pathname: '/search',
search: `?q="${value}"`,
}}
/>
);
}
return (
<ReactiveBase
...>
<DataSearch
...
/>
{ pathname === '/results'
? <Results />
: null
}
</ReactiveBase>
);
}
}
export default withRouter(SearchContainer);