If you want to keep using your phone after you’ve wiped the contents, you can recover the content from your backup. Here’s How it works:
How to restore an iPhone via iCloud backup
Step 1: After you’ve completed the factory reset, you’ll need to start over with the configuration of your iPhone:

Step 2: Start the iPhone and enter your details, including your WiFi password, until you reach the page asking how you want to ‘Set Up iPhone.’
Step 3: You now have three options: Set Up as a New iPhone, Restore from iCloud Backup, or Restore from iTunes Backup. Choose Restore from iCloud Backup and you’ll be asked to enter your iCloud account details.
Step 4: Your iPhone will begin restoring all of your data once you’ve completed this and agreed to the terms and conditions.

If you have a lot of backups or a weak internet connection, this can take a long time, so don’t do it if you’re in a hurry. Your iPhone will reboot after the backup is complete, and it will then begin the larger task of downloading all of your applications.
Also Read: How to factory reset iphone
How to restore an iPhone via iTunes or Finder backup
Step 1: Follow the steps up to the ‘Set Up iPhone’ tab, then pick Restore from iTunes, just as we did with the iCloud instructions.

Step 2: Connect to iTunes will be prompted, so plug in your iPhone and you’ll see a screen on iTunes with the option to restore a backup. When you click Proceed, your iPhone will be automatically set up, with the software restored from your iTunes backup.

Step 3: When it’s done, the machine will be thoroughly cleaned. Hopefully, any issues you were having before would be resolved.

Step 4: If you upgrade to macOS Catalina, iTunes will no longer be accessible, but Finder will perform the functions mentioned above. In that application, follow the same instructions.