const myState = {
users: [],
hospitals: []
}
const myReducer = (state = myState, action) => {
if( action.type === 'FETCH_DATA' ) {
return myState[action.storeType].concat(data)
}
return state
}
const fetchData = (url) => {
fetch(...).then(data => {
return {
type: "FETCH_DATA",
data: data.result,
storeType: data.type
}
})
}
map
подходит только для массивов.Object.keys(yourPropObject).map(item => {
return <p> {yourPropObject[item].title} </p>
})