Wednesday, July 5, 2023

149: Lifting State With Context

 All of our web3 logic is location in our Transaction Context, allowing the functions to be accessible everywhere in the app. However, in order for our frontend to interact with the blockchain, we need to read values from the form in the Welcome component and pass them to the functions in our context. How is this possible? A solution is to lift the state from the Welcome component into the context, and create an object in state that holds the values of the forms. We also create a handleChange function, that updates the form state appropriately based on which field is being modified. We can then pass this state and function via our context, to make them available to our component and connect them to the form. This way all our web3 logic can be neatly contained in our context, and the various functions can be passed accordingly and connected to forms and buttons as needed. 

No comments:

Post a Comment

190: Sablier

 The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...