React native React Native:在道具中传递关键字以进行搜索

React native React Native:在道具中传递关键字以进行搜索,react-native,react-props,React Native,React Props,在一个小问题上我需要一点帮助。在我的第一个屏幕中,我有一个包含一些关键字的平面列表。我想,如果我点击任何关键字,我应该被导航到另一个屏幕与该关键字的道具。我在平面列表中这样做: <FlatList data={myRecentSearches} renderItem={({ item, index }) => ( <TouchableOpacity onPress={() => props.navigation.navigate(

在一个小问题上我需要一点帮助。在我的第一个屏幕中,我有一个包含一些关键字的平面列表。我想,如果我点击任何关键字,我应该被导航到另一个屏幕与该关键字的道具。我在平面列表中这样做:

<FlatList
    data={myRecentSearches}
    renderItem={({ item, index }) => (
    <TouchableOpacity
         onPress={() => props.navigation.navigate("search", { searchValue: `${item.keyword}` })}>
          <Text>{item.keyword}</Text>
    </TouchableOpacity>
)}
(
props.navigation.navigate(“search”,{searchValue:`${item.keyword}}}}>
{item.keyword}
)}
在下一个屏幕中,我希望输入字段已经用该关键字初始化

const SearchScreen = (props) => {
  const [searchValue, setSearchValue] = useState("");
  return (
    <View activeOpacity={0.5} style={styles.searchContainer}>
        <TextInput
          allowFontScaling={false}
          value={searchValue} //I want this value to be already initialized/populated with the prop
          returnKeyType="search"
          autoFocus
          />
      </View>
  )
}
const SearchScreen=(道具)=>{
常量[searchValue,setSearchValue]=useState(“”);
返回(
)
}

在您的第一个屏幕中,搜索屏幕如下所示:

return(
<SearchScreen keyWord={item.keyword}/>
)
返回(
)
和内部搜索屏幕:

const SearchScreen = (props) => {
  const [searchValue, setSearchValue] = useState(props.keyWord);
  return (
    <View activeOpacity={0.5} style={styles.searchContainer}>
        <TextInput
          allowFontScaling={false}
          value={searchValue} //I want this value to be already initialized/populated with the prop
          returnKeyType="search"
          autoFocus
          />
      </View>
  )
}
const SearchScreen=(道具)=>{
const[searchValue,setSearchValue]=useState(props.keyWord);
返回(
)
}

我怎么能在第一个屏幕上有这样的搜索组件?你说的是什么意思?更新了答案。最后一件事,女士,我应该在第一个屏幕的平面列表中,在onPress函数中,将return()放在哪里?将非常感谢您的帮助:)不不,不,在您放置其他div的地方返回,例如:
…您的其余代码。。。return(…此处显示其他内容…)