You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
799 B

import React, { useState, useContext } from 'react';
import ViewBudget from './ViewBudget';
import EditBudget from './EditBudget';
import { AppContext } from '../context/AppContext';
const Budget = () => {
const { budget, dispatch } = useContext(AppContext);
const [isEditing, setIsEditing] = useState(false);
const handleEditClick = () => {
setIsEditing(true);
};
const handleSaveClick = (value) => {
dispatch({
type: 'SET_BUDGET',
payload: value,
});
setIsEditing(false);
};
return (
<div className='widget d-flex align-items-center justify-content-between'>
{isEditing ? (
<EditBudget handleSaveClick={handleSaveClick} budget={budget} />
) : (
<ViewBudget handleEditClick={handleEditClick} budget={budget} />
)}
</div>
);
};
export default Budget;