Skip to content

Bug in Budget.js? #392

@HavidDartmann

Description

@HavidDartmann

Hello,

I copied the code block for the budget.js file. Anyways when I run the website the budget state will not be updated in the context. Therefore I changed the file to this.

import { AppContext } from '../context/AppContext';

const Budget = () => {
    const { budget, dispatch } = useContext(AppContext);
    const [newBudget, setNewBudget] = useState(budget);
    const handleBudgetChange = (event) => {
        setNewBudget(event.target.value);
        dispatch({
            type: 'SET_BUDGET',
            payload: event.target.value
        });
    }
    return (
<div className='alert alert-secondary'>
<span>Budget: £{budget} </span>
<input type="number" step="10" value={newBudget} onChange={handleBudgetChange}></input>
</div>
    );
};
export default Budget;

Here I just added the dispatch function, because in the tutorial there is none. Please let me know if I am wrong or if this is a real issue in your repo.

Best Regards,
David

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions