Best practice for "filter" functions?
What is the best practice for functions that don't alter state, but just return a subset of state? Eg. show todos that start with 'a'? Or if I have a cart that is an array of product ids, and I want the array of products based on those ids.
Thanks in advance.
@jeberly what's about using reselect for example ? I mean, I think we should filter/sort our data right before rendering it. The state should remains the same. By this way we can use the same data to rendering on different components plus different filters and with no data replication.
+1 to @horaciosystem's point about avoiding duplicated data. It seems like those 2 example problems would be best suited to a selector:
@connect( (state, props) => {
let todos = state.todos.filter( todo => todo.text.indexOf(props.search) !== -1 );
return { todos };
})
class List extends Component {}