取東西我一直有麻煩試圖建立終極版,我已經mapStateToProps和mapDispatchToProps設置和我的動作和減速,但每當我試圖輸出任何我映射的道具我不能獲取從道具我有什麼關係映射狀態。廣東話從終極版
我已經回到我的index.js並嘗試使用alert(store.getState())和alert(store.getState()。value1)和alert(store.getState(value1))之後我知道value1已被派遣,通過我的行動,我的減速器,然後(希望)通過我的商店。我也曾嘗試在mapStateToProps中使用的prop上使用警報
我得到的唯一輸出是store.getState()的空白警報,對於其他選項未定義。
我不知道什麼是我的代碼腳麻:(
動作/ index.js:
export const updateDial1 = (value1, value2) => {
return {
type: 'UPDATE_DIAL_1',
value1,
value2
}
}
減速器/ reducer.js
const update = (state, mutations) => Object.assign({}, state, mutations)
const valuesReducer = (state = [], action) => {
switch (action.type) {
case 'UPDATE_DIAL_1':
{
return [
...state,
{
value1: action.value1,
value2: action.value2,
}
]
}
}
export default valuesReducer
組件/組件。 js
(取出組件)
// use this to apply values from redux store to local props
const mapStateToProps = state => ({
valuesReducer: state
})
// use this to send changes to the Redux store
const mapDispatchToProps = {
updateDialLine1: actions.updateDial1
}
和export default connect(mapStateToProps, mapDispatchToProps)(CustomComponent)
與商店聲明index.js:(所述的console.log返回一個空數組)
import React, { Component } from 'react';
import { Root } from './navigator/router';
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { createStore } from 'redux'
import valuesReducer from './reducers/dials'
let store = createStore(valuesReducer)
export default class App extends Component {
render() {
// setTimeout(() => {console.log(store)}, 15000)
return (
<Provider store={store}>
<Root />
</Provider>
);
}
}
在一個側面節點,而不是調試與'警報()','青睞的console.log()' 。在目前情況下更好,請在瀏覽器中安裝redux擴展。 – Delapouite
您可以添加商店初始化嗎?我想看看你如何註冊你的減速器。 – Okazari
現在就爲你添加。 –