Reputation: 2204
Can the App
component have its state in the constructor and simultaneously fetch data fromstore
in redux? I am asking because if I remove connect
andmapStateToProps
, this.state.tasks.filter
works normally. And when I add connect
andmapStateToProps
, I have the error filter
is not function.
class App extends Component {
constructor() {
super();
this.state = {
tasks: []
}
}
render() {
const filterTasks = this.state.tasks.filter........
return (
<ul>
</ul>
);
}
}
const mapStateToProps = state => {
const {todos} = state;
return {
todos
};
};
export default connect(
mapStateToProps
)(App);
Upvotes: 1
Views: 36
Reputation: 6005
Yes, the mapStateToProps
functions give the value from redux
store as props to the component App
inside App
you can get redux state
in this.props.todos
Upvotes: 1