Created
March 14, 2021 20:05
-
-
Save ligabloo/db518cc05009769c4f7d3694af9e07e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SearchContext = createContext({}); | |
const SearchProvider = ({children}) => { | |
const [artistsData, setArtistsData] = useState([]); | |
const [searchTerm, setSearchTerm] = useState([]); | |
async function fetchArtistsData() { | |
// ..pega dados dos artistas | |
setArtistsData(data); | |
} | |
useEffect(() => { | |
fetchArtistsData() | |
}, []); | |
const filteredArtists = artistsData.filter(artist => artist.name.includes(searchTerm)); | |
const artistCount = filteredArtists.length; | |
return ( | |
<SearchContext.Provider | |
value={{ | |
artistsData, | |
searchTerm, | |
setSearchTerm, | |
filteredArtists, | |
artistCount | |
}} | |
/> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment