components/SearchHeader.js
import React, {useContext} from 'react'; import { Pressable, StyleSheet, TextInput, useWindowDimensions, View, } from 'react-native'; import Icon from 'react-native-vector-icons/MaterialIcons'; import SearchContext from '../contexts/SearchContext'; function () { const {width} (); const {keyword, onChangeText} = useContext(SearchContext); return ( <View style={[styles.block, {width width - 32}]}> <TextInput style={styles.input} placeholder="검색어를 입력하세요" value={keyword} onChangeText={onChangeText} autoFocus /> <Pressable style={({pressed}) => [styles.button, pressed && {opacity 0.5}]} onPress={() => onChangeText('')}> <Icon name="cancel" size={20} color="#9e9e9e" /> </Pressable> </View> ); } (...)
SearchScreen에는 임시로 Text를 사용해 검색어를 화면에 보여주도록 설정합시다. SearchContext가 잘 작동하고 있는지 검증하기 위해서입니다.