In package.json add the following in this order:
"homepage": "https://{your-github-name}.github.io/{name-of-your-repo}"
in the Scripts section, add:
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
Save and commit Changes.
Push your changes to github.
Finally, in the terminal run:
npm run build
Your react app will be successfully deployed to github pages