Reputation: 83
I am working with reducer It sems reduct can connect to redux but unfourtunatly state can not connect with props. I have seen state value but it not connect with props .could you anyone help me to find how can i assaign state to props please
1-reducer_books.js
------------------------------------------------------
export default function () {
return [
{ title: 'testTitle1' },
{ title: 'testTitle2' },
{ title: 'testTitle3' },
{ title: 'testTitle4' },
{ title: 'testTitle5' }
]
}
---------------------------------------------------
2-book-list.js
---------------------------------------------------
import React,{Component} from 'react';
import {connect} from 'react-redux'
class BookkList extends Component {
renderLis() {
return
this.props.books.map((book) => {
return (
<li className='list-group-item' key={book.title}> {book.title}</li>
);
});
}
render(){
return(
<ul className="list-group col-sm-4">
{this.renderLis()}
</ul>
)
}
}
function mapStateToProps(state) {
console.log("mapStateToPropsInfo: ", state)
return {
books: state.books
}
}
export default connect (mapStateToProps) (BookkList)
--------------------------------------------------
3-app.js
-------------------------------------------------
import React, { Component } from 'react';
import BookkList from '../containers/book-list'
export default class App extends Component {
render() {
return (
<div>
<BookkList />
</div>
);
}
}
------------------------------------------------
4-index.js
-------------------------------------------------
import { combineReducers } from 'redux';
import BookReducer from './reducer_books';
const rootReducer = combineReducers({
books:BookReducer
});
export default rootReducer;
I am working with reducer It sems reduct can connect to redux but unfourtunatly state can not connect with props. I have seen state value but it not connect with props .could you anyone help me to find how can i assaign state to props please
Upvotes: 0
Views: 187
Reputation: 1975
You will get the props value in your method "renderLis()". Reason behind this is, mapStateToProps has the Store state as an argument/param (provided by react-redux::connect) and is used to link the component with certain part of the store state.
By linking I mean the object returned by mapStateToProps will be provided at construction time as props and any subsequent change will be available through componentWillReceiveProps. So if you want to check the props value you can either check it by logging console in 'componentWillReceiveProps' lifecycle method or in your renderLis() where component gets rendered.
Upvotes: 1