0

I try to console.log the data I've been receiving from RAPID API bing news, but when I tried to pull it out, it says Object(...) is not a function. When I try to remove the line 6 of News.js it renders, but if I put it back it returns the same problem

News.js

import { Select, Typography } from 'antd'
import { useGetCryptoNewsQuery } from '../services/cryptoNewsApi'
const {Text, Title} = Typography
const { Option } = Select
const News = ({simplified}) => {
    const { data: cryptoNews} = useGetCryptoNewsQuery({newsCategory: 'Cryptocurrency', count: simplified ? 6 : 12})
    console.log(cryptoNews)
    return(
        <div>
            <h1>Hello</h1>
        </div>
    )
     
    
}

export default News

store.js

import { configureStore } from '@reduxjs/toolkit'
import { cryptoApi } from '../services/cryptoApi'
import { cryptoNewsApi } from '../services/cryptoNewsApi'

export default configureStore({
  reducer: {
    [cryptoApi.reducerPath]: cryptoApi.reducer,
    [cryptoNewsApi.reducerPath]: cryptoNewsApi.reducer,
  },
})

cryptoNewsApi.js

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/dist/query'

const cryptoNewsHeaders = {
  'x-bingapis-sdk': 'true',
  'x-rapidapi-host': 'bing-news-search1.p.rapidapi.com',
  'x-rapidapi-key': 'API-KEY',
}

const baseUrl = 'https://bing-news-search1.p.rapidapi.com'

const createRequest = (url) => ({ url, headers: cryptoNewsHeaders })

export const cryptoNewsApi = createApi({
  reducerPath: 'cryptoNewsApi',
  baseQuery: fetchBaseQuery({ baseUrl }),
  endpoints: (builder) => ({
    getCryptoNews: builder.query({
      query: ({ newsCategory, count }) =>
        createRequest(
          `/news/search?q=${newsCategory}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${count}`
        ),
    }),
  }),
})

export const { useGetCryptoNewsQuery } = cryptoNewsApi

1 Answers1

0

I believe Automatic Semicolon Process doesn't happen. Try inserting a semicolon at the end of the statement.

const { data: cryptoNews} = useGetCryptoNewsQuery({newsCategory: 'Cryptocurrency', count: simplified ? 6 : 12});
Pratham
  • 497
  • 3
  • 7