import React, { useEffect } from "react"; import { Searchbar } from 'react-native-paper'; import { StyleSheet, SafeAreaView, FlatList, Text } from 'react-native'; import API from "../API"; import ProfileCardHorizontal from "../components/ProfileCardHorizontal"; import { useSnapshot } from 'valtio'; import GlobalState from '../contexts/GlobalState.js'; const Search = () => { const viewer = useSnapshot(GlobalState).me; const [searchQuery, setSearchQuery] = React.useState(''); const [profiles, setProfiles] = React.useState([]); const [queryTimer, setQueryTimer] = React.useState(0); useEffect(() => { let subscribed = true; API.searchProfiles('').then((data) => { if (subscribed) setProfiles(data.profiles || []); }); return () => { subscribed = false; } }, []) const onChangeSearch = query => { setSearchQuery(query); if (queryTimer) clearTimeout(queryTimer); let timerId = setTimeout(() => { API.searchProfiles(query).then((data) => { setProfiles(data.profiles || []); }); }, 300); setQueryTimer(timerId); }; const renderProfile = (({ item }) => { return (); }); const renderFollowing = (({ item }) => { return (); }); return ( { searchQuery.length ? item._id} /> : <> Current Following: item} /> } ) } export default Search; const styles = StyleSheet.create({ container: { padding: 5, }, });