Scenario: Auto-Completion
- The value of a HTML
input
-element's is transfered to a redux-state. - This redux-state defines a query that is injected with tracker (as illustrated below).
- The result of the query is displayed as auto-complete-options.
Problem: Component does not reload on input
-value change
How can the component be reloaded, when the input
-value changes?
Code-Snippet
const AutoComplete = (props) => {
let handleChange = (event) => {
props.setSearchQuery(event.target.value);
};
return (
<div>
<input
type="text"
onChange={(event) => handleChange(event)}
/>
</div>
);
};
export default connect(
(state) => ({
searchQuery: selectors.getSearchQuery(state)
}),
(dispatch) => ({
setSearchQuery: (queryString) => dispatch(actions.setSearchQuery(queryString))
})
)(
composeWithTracker(
(props, onDate) => {
const searchResults = props.searchFunction(props.searchQuery);
onDate(null, {searchResults});
}
)(AutoComplete)
);
I think it's because you dispatch an action. but the props of AutoComplete doesn't change, so the component will not render.
just make sure
searchQuery
props is used in your component