{"size": 1406, "ext": "js", "max_stars_repo_path": "client/src/pages/Search/index.js", "max_stars_repo_name": "Tuppince24/RTS-Lab-Exercise", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/pages/Search/index.js", "max_issues_repo_name": "Tuppince24/RTS-Lab-Exercise", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/pages/Search/index.js", "max_forks_repo_name": "Tuppince24/RTS-Lab-Exercise", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.6666666667, "max_line_length": 82, "alphanum_fraction": 0.4864864865}
import React, { useState, useEffect } from 'react';
import SearchForm from '../../componets/SearchForm'
import SearchResults from '../../componets/SearchResults'
import API from '../../utils/API'

function Search(){
    const [search, setSearch] = useState("Hacker News");
    const [title, setTitle] = useState("")
    const [author, setAuthor] = useState("")
    const [url, setUrl] = useState("");

    useEffect(() =>{
        if(!search){
            return;
        }
        API.searchTerms(search)
            .then(res => {
              console.log(res.data)
              setAuthor(res.data[1]);
              setUrl(res.data[1])  
              console.log("mu log" + res.data);
              console.log(res.data.hits)
              setTitle(res.data.hits.map(results => {return `${results.title}`;}))
              console.log(setTitle)
              
            })
            .catch(err => {
                console.log(err);
            })
    }, [search]);

    

    
    const handleInputChange = event =>{
        setSearch(event.target.value);
    }

    return(
        <div>
            <SearchForm
            handleInputChange={handleInputChange}
            results={search}
            />
            
            <SearchResults
            title={title}
            author={author}
            url={url}
            />
        </div>
        
    )
};

export default Search;
