รายละเอียดสำหรับเรียนรู้ React ปี 2020-2023 โดยโค้ชพล ดูหลักสูตรได้ที่ https://www.nextflow.in.th/react-training
หลังจากเราทำ action แรกเสร็จแล้ว เราก็จะใช้รูปแบบเดียวกับ Action แรกในการสร้าง
เราจะสร้าง function ชื่อ showBranchChart
เพื่อส่งต่อข้อมูลเข้า reducer
export const showBranchChart = (branchData, dispatch) => {
console.log('Branch Data', branchData);
dispatch({
type: ActionType.SHOW_BRANCH_CHART,
payload: branchData
});
}
export const ActionType = {
GET_BRANCH_LOCATION_FINISH: 'GET_BRANCH_LOCATION_FINISH',
SHOW_BRANCH_CHART: 'SHOW_BRANCH_CHART'
};
export const getBranchLocation = async (dispatch) => {
console.log('getting data');
let api = 'https://www.nextflow.in.th/api/branch-info/branch.json';
let response = await fetch(api);
let json = await response.json();
console.log(json);
dispatch({
type: ActionType.GET_BRANCH_LOCATION_FINISH,
payload: json.branches
});
}
export const showBranchChart = (branchData, dispatch) => {
console.log('Branch Data', branchData);
dispatch({
type: ActionType.SHOW_BRANCH_CHART,
payload: branchData
});
}