Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Budget.js? #392

Open
HavidDartmann opened this issue Mar 27, 2024 · 1 comment
Open

Bug in Budget.js? #392

HavidDartmann opened this issue Mar 27, 2024 · 1 comment

Comments

@HavidDartmann
Copy link

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

@Irascibleardent
Copy link

Had same issue and used same fix, as well as deleting the {budget} after the pound symbol. Still hasn't been fixed in the main branch as of this posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants