ibm-developer-skills-network / ejtos-react_budget_app

react_budget_app
Apache License 2.0
34 stars 7.49k forks source link

Bug in Budget.js? #392

Open HavidDartmann opened 4 months ago

HavidDartmann commented 4 months ago

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 commented 2 months ago

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.