ahhzaky / google-clone

This is a Google-Clone with API Google Search and this app responsive.
MIT License
1 stars 0 forks source link

useGoogleSearch.js #12

Open ahhzaky opened 4 years ago

ahhzaky commented 4 years ago

use HOOKS.

const CONTEXT_KEY = "FROM GOOGLE programmable search";

function 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;

ahhzaky commented 4 years ago

2:24:00 from video