Check out example codes for "viacep Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.". It will help you in understanding the concepts better.
Code Example 1
npm install --save cep-promise ... import * as cep from 'cep-promise' cep('05010000') .then(console.log)
Learn ReactJs, React Native from akashmittal.com