Lifting up the State
Learn how to lift up the state.
We'll cover the following...
Imagine we’re working on a business card editor. We need to create a form that will allow users to upload their pictures and information such as their name, description, phone number, and address.
Implementation
Let’s start by creating two files in a newly scaffolded project. The BusinessCardEditor component imports and renders the BusinessCardForm component.
It’s good practice to keep the state close to where it belongs, so it does make sense to put it in the form component.
Let’s also update the routes config so we can access it.
We now have a working form that’s synchronized with the component state. The functionality is done, but now the client is asking to add a nice preview of this form that looks like a business card (as shown in the business card editor figure).
The easiest solution would be to simply add code for the preview in the BusinessCardForm ...