我将状态钩子作为道具传递给我的组件,并且我的 HeaderButton 工作得很好,但是当我尝试实现 onPress 时,我收到一条错误消息“props.setActiveTab 不是函数”
import React from "react";
import { useState } from "react";
import { View, Text, TouchableOpacity } from "react-native";
export default function Header(props) {
const [activeTab, setActiveTab] = useState("Delivery");
return (
<View style={{ flexDirection: "row", alignSelf: "center"}}>
<HeaderButton
text="Delivery"
bgColor="black"
textColor="white"
activeTab={activeTab}
setActiveTab={activeTab}
/>
<HeaderButton
text="Pick up"
bgColor="white"
textColor="black"
activeTab={activeTab}
setActiveTab={activeTab}
/>
</View>
);
}
const HeaderButton = (props) => (
<TouchableOpacity
style={{
backgroundColor: props.activeTab === props.text ? "black" : "white",
paddingVertical: 10,
paddingHorizontal: 40, …Run Code Online (Sandbox Code Playgroud)