I'm trying to conditionally render my Results component from within ReactiveBase, but every time I try to use a ternary operator it breaks the rendering. If I remove the ternary, results display.
I'm using the <ReactiveList>
component to display the results in my Results component.
I only want results to display if a user has ACTUALLY submitted a search query. So how can I conditionally render the Results component from within ONLY after a user has submitted a query
Here is my code so far:
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);