Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
'API_KEY' is defined but never used 'CONTEXT_KEY' is assigned a value but never used

I've created a file called keys.js, where it houses my API_KEY. I've exported it from that file and imported it into my useGoogleSearch.js file. However, it's not properly importing and my error keeps returning as "'API_KEY' is defined but never used 'CONTEXT_KEY' is assigned a value but never used Unexpected template string expression".

I think it has to do with my url - 'https://www.googleapis.com/customsearch/v1? key=${API_KEY}&cx=${CONTEXT_KEY}&q=${term}'.

import { useState, useEffect } from "react";
import API_KEY from "./keys";

const CONTEXT_KEY = "ANOTHER KEY";

const useGoogleSearch = (term) => {
    const [data, setData] = useState(null);

    useEffect(() => {
        const fetchData = async() => {
            fetch('https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${CONTEXT_KEY}&q=${term}')
                .then(response => response.json())
                .then(result => {
                    setData(result)
                })
         }

        fetchData();
     }, [term])

     return { data };
};

export default useGoogleSearch
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You defined your API URL as a string here.

fetch('https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${CONTEXT_KEY}&q=${term}')

So your variables API_KEY and CONTEXT_KEY are not evaluated as values. Instead, use Template literals.

fetch(`https://www.googleapis.com/customsearch/v1?key=${API_KEY}&cx=${CONTEXT_KEY}&q=${term}`)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!