Instructor: Let's take a look at the infamous Counter example, first as a regular React component then as a PowerPlug component. As you can see here, I have a simple class component with a Counter for State and two handlers for incrementing and decrementing.
The first component you'll find in the React PowerPlug library is the State component. All additional components in the library are built using the State component, and it's what we'll use to get started with our Refactor.
The first thing we'll need to do is wrap our component with a State component and pass it in an initial value for our State. Remember, the React PowerPlug library doesn't render any DOM itself but acts more as a container for your State and logic that you can pass to your UI. It does this in the form of the Render props pattern which allows us to render whatever we want.
This State PowerPlug component will give use two parameters we can use in our component -- State and Substate. All right, so let's got ahead and adjust our existing implementation to utilize the params provided in our render prop.
This .state.counter can be replaced with just state.counter, and our event handlers can simply be in line and called a set State method directly. The main advantage to this pattern is the clean separation between State logic and the presentational component in charge of rendering the UI.
The State component is agnostic at what it's rendering. It just supplies the UI component with the necessary tools to get its job done. All right, so that looks like it's working. Let's go ahead and clear out our existing component to clean it up a bit.