我有使用react-router
一個基本的網站設置,我的索引頁:陣營路由器連接到終極版
render(
<Provider store={store}>
<Router history={browserHistory} routes={routes} />
</Provider>,
document.getElementById('root')
);
減速機:
import { ADD_DETAILS } from '../constants/ActionTypes';
const initialState = [
{
id: 0,
language: '',
session: '',
values: '',
accessCode: '',
age: 0,
gender: '',
ethnicity: '',
drinkOften: '',
drinkConcern: '',
},
];
export default function UserDetails(state = initialState, action) {
switch (action.type) {
case ADD_DETAILS:
// update user details
default:
return state;
}
}
指數減速器:
import { combineReducers } from 'redux';
import UserDetails from './UserDetails';
const rootReducer = combineReducers({
UserDetails,
});
export default rootReducer;
典型網頁看起來是這樣的:
class Screen1 extends Component {
constructor() {
super();
this.submitForm = this.submitForm.bind(this);
}
submitForm(e) {
const language = e.target.value;
//dispatch action here - this.props.UserDetails
}
render() {
return (
<div>
<label htmlFor="title">Please select your language</label>
<button
className="btn btn-primary"
value="en"
onClick={this.submitForm}>
English
</button>
<button
className="btn btn-primary"
value="po"
onClick={this.submitForm}>
Polszczyzna
</button>
</div>
);
}
}
export default connect()(Screen1);
我已經加入:
function mapStateToProps(state, ownProps) {
return {
UserDetails: state.UserDetails,
};
}
export default connect(mapStateToProps)(Screen1);
在我的行爲我有這個addDetails
動作,我怎麼能派遣它從我的頁面:
import * as types from '../constants/ActionTypes';
export const addDetails = (id, text, time) => ({
type: types.ADD_DETAILS,
text,
id,
time,
});
我怎樣才能派遣行動在我的網頁?我看不到道具中的派送。
我不能看到我的行動調度th他們,'this.props.addDetails'是空 – Bomber
你只添加mapStateToProps而不是mapsDispatchToPropsof – pinturic