减速器是这样的:
import {
CREATE_COUNTRY,
} from "../actions/actionConsts"
export const storeInitialState = {
countries: [],
otherThings: 0
}
export default function countriesReducer(prevState = storeInitialState, action) {
switch (action.type) {
case CREATE_COUNTRY:
return {
...prevState,
countries: [
...prevState.countries,
action.country
]
}
default:
return prevState
}
}
动作 Creator 是
export function createCountryActn(country) {
return {
type: CREATE_COUNTRY,
country
}
}
以及我触发动作的组件
… … … … …
createTheCountry = (e) => {
e.preventDefault()
this.props.createCountry(this.state.name)
this.setState({
name: '',
})
}
… …… … … …
是什么导致商店的状态在每次添加新商品时重新启动?
拉斐尔