This can be frustrating, but there are a few potential solutions you can try before seeking professional help.
First, make sure you're using a genuine Apple charging cable and adapter. Using third-party accessories can sometimes lead to compatibility issues. Try using a different cable and adapter to see if the problem persists.
If that doesn't work, you can attempt a hard reset by simultaneously holding down the volume down button and the power button until you see the Apple logo. This may help resolve any temporary software glitches causing the restarts.
Another step is to check for any pending software updates. Outdated software can sometimes lead to unusual behavior in your iPhone. To do this, go to Settings > General > Software Update and install any available updates.
If none of these solutions work, it's possible that there might be a more serious hardware issue. In that case, it's best to contact Apple Support or visit an Apple Store for professional assistance. They can diagnose the problem and provide a solution, whether it's a repair or a replacement.