21
loading...
This website collects cookies to deliver better user experience
index.js
file.import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, applyMiddleware } from 'redux'
import { Provider } from 'react-redux'
import thunk from 'redux-thunk'
import rootReducer from "./reducers/rootReducer"
import { composeWithDevTools } from 'redux-devtools-extension'
import './index.css'
import App from './App'
import { BrowserRouter as Router } from 'react-router-dom';
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))
ReactDOM.render(
<Router>
<Provider store={store}>
<App />
</Provider>
</Router>,
document.getElementById('root')
)
createStore
function, the rootReducer
file, and <Provider>
tags. My variable store
is what is created when the function createStore
runs. The rootReducer
file takes in my reducer functions which are responsible for returning the next state tree, given the current state tree and an action. More on that later.<Provider>
comes in. By Wrapping the <App />
component in the <Provider>
and giving it the store
, we give every child component of <App />
the ability to access the store no matter where they fall in the hierarchy of components.import { connect } from 'react-redux'
...
const mapStateToprops = (state) => {
return{
movie: state.movies,
}
}
export default connect(mapStateToprops)(MovieCard)
movies
as props to my component with the key of movie:
. So in this component I can now display the current state. My project, where this code is from, searches an API to return movie data. So in my component I can display things now like {this.props.movie.title}
.