--cart.js
<tbody>
{state.map((data,idx) =>(
<tr key={idx}>
<td>{data.id}</td>
<td>{data.name}</td>
<td><button onClick={()=>{ state.dispatch({type:'수량증가', id:data.id})}}>+</button> 1 <button>-</button></td>
<td>{data.price}</td>
</tr>
))}
</tbody>
-- index.js
function reducer(state = init, action){
let copy = [...state]; //deep copy
if(action.type === '수량증가'){
let d = copy.find( a => a.id === action.id);
d.quan++;
return copy
}else if(action.type === '수량감소'){
let d = copy.find( a => a.id === action.id);
d.quan--;
return copy
}else{ //기본값 리턴
return copy
}
}
let store = createStore(reducer);
TypeError: state.dispatch is not a function 에러가 뜨는데 원인을 도무지 모르겠습니다 ㅠㅠ