- Go to https://newsapi.org/
- Login or create an account
- Then click on your email-ID from navbar and you will be redirected to your account page and from there you can copy your API KEY.
- Once you get API KEY you need yo add that key in
src/components/News.js
file.
// Replace <API KEY> to your key and make sure to remove <> brackets.
async componentDidMount() {
let url = "https://newsapi.org/v2/top-headlines?country=in&apiKey=<API KEY>&page=1";
let data = await fetch(url);
let parsedData = await data.json()
console.log(parsedData);
this.setState({articles: parsedData.articles})
}
- Run command
npm install
in terminal. - Then run the command
npm start
in terminal.