#From EggHead
- State tree is redonding (can't modify)
- Action is the representation of the change of the data
- need to have type property (can't be undefined)
- We can change the
State
tree by dispatching anAction
(JS Object) - Component dispatch
action
#App State with redux
__Component State !== Application State
Redux in charge of the application state
React provides views to display state
Application state generated by reducer function
##Folders
###Reducers folder: reducers_books.js -> array containing list of object where each object contains list of books with title as key index.js ->
import { combineReducers } from 'redux';
import BooksReducer from './reducer_books';
//_book reducer added to combineReducers_
const rootReducer = combineReducers({
//_reducer add key (books) and value of what returns (BooksReducer=array of books) to the global application state_
books: BooksReducer
});
export default rootReducer;
###Containers folder
Book_list.js
depends on the state so had to be "promoted" in the container folder
####difference with components folder:
import { connect } from 'react-redux';
to be able to use the connect
function linking React and Redux libraries
function mapStateToProps( state ) {
// Whatever it returned will show up as props inside of BookList
return {
books: state.books
};
}
export default connect( mapStateToProps )( BookList )
in app.js
make sure BookList is rendered.