'useReducer Cannot set properties of undefined after second attempt to edit the value

For some reason combo of useReducer and useContext is not working out for me, as you can see from the code I'm trying to change the value using the onChange and it works for the first time but the second time everything crashes. Here's link to the code https://codesandbox.io/s/billowing-field-k7lif?file=/src/App.css Ps: App.js , and Surcharge are the files to check out. (ignore the comments)



Solution 1:[1]

<ContextOne.Provider value={{ initialState, dispatch }}> Naturally, initialState never changes and is, in fact, just the initial state, so all zeroes. What I needed to do was this:

<ContextOne.Provider value={{ state, dispatch }}>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1