Stack Overflow на русском Asked by hidden gen on January 4, 2022
Не могу понять почему при коннекте компонента Header со store, state не доходит до props. При поптыке вывести props выводится пустой объект. При этом в redux devtools показывается, необходимая структура state. В чем проблема? Заранее спасибо.
// roorReducer
import {combineReducers} from "redux"
import {headerReducer} from "./headerReducer"
export const reducer = combineReducers({
header: headerReducer,
})
// headerReducer
const initialState = {
routes: [
{to: '/', text: 'Главная'},
{to: '/catalog', text: 'Каталог'},
{to: '/partners', text: 'Партнеры'},
{to: '/reviews', text: 'Отзывы'},
{to: '/team', text: 'Команда'},
{to: '/contacts', text: 'Контакты'},
{to: '/blog', text: 'Блог'},
]
}
export const headerReducer = (state = initialState, action) => {
return state
}
// компонент Header
import React from "react"
import {connect} from 'react-redux'
export const Header = props => {
return (
<header className={'header'}></header>
)
}
const mapStateToProps = state => {
return state
}
export default connect(mapStateToProps, null)(Header)
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import * as serviceWorker from './serviceWorker'
import App from './App'
import {Provider} from 'react-redux'
import {compose, createStore} from 'redux'
import {reducer} from "./redux/reducers/reducer"
const store = createStore(reducer, compose(
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
))
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
)
serviceWorker.unregister()
Дело было с том, что я экспортировал Header до того, как совершу коннект к store.
Answered by hidden gen on January 4, 2022
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP