Redux Bad Practices #4: Duplicate State

onFilterChange(filter) {
this.setState({
filteredProducts: this.props.products.filter(...)
})
}
mapStateToProps = (state) => ({
filteredProducts: filteredProductsSelector(state)
})
render() {
const filteredProducts = this.props.products.filter(...);
return <div>{ filteredProducts.map(...) }</div>;
}
myComp({ products }) {
const filteredProducts = useMemo(
() => products.filter(...), [products]
);
return <div>{ filteredProducts.map(...) }</div>;
}

--

--

http://adamklein.dev/ I write code, and speak about it

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store