Javascript 我需要在React Native中传递一个带有TouchableOpacity的值

Javascript 我需要在React Native中传递一个带有TouchableOpacity的值,javascript,react-native,Javascript,React Native,我需要更改信息,按flatlist项并显示在principal视图中 我的主要问题是用touchableOpacity更改信息 export default function HomeScreen() { const [isLoading, setLoading] = useState(true); const [data, setData] = useState([]); const actualNoticia = data[2]; useEffect(() => {

我需要更改信息,按flatlist项并显示在principal视图中 我的主要问题是用touchableOpacity更改信息

export default function HomeScreen() {
  const [isLoading, setLoading] = useState(true);
  const [data, setData] = useState([]);
  const actualNoticia = data[2];

  useEffect(() => {
    fetch('http://newsapi.org/v2/top-headlines?country=mx&apiKey=7b1bcdb1cbe04f709b69c0ef4f9c323b')
      .then((response) => response.json())
      .then((json) => setData(json.articles))
      .catch((error) => console.error(error))
      .finally(() => setLoading(false));
  }, []);

  const renderItem = ({ item }) => (
    <TouchableOpacity>
    <View style={styles.itemHorizontal}>
      <View style={{ flex: .9, width: windowWidth * .95, padding: 10, backgroundColor: Colors.ColorPrincipal, borderRadius: 5, flexDirection: 'row' }}>
        <View style={{ flex: .4 }}>
          <Image source={{ uri: item.urlToImage }} resizeMode='cover' style={{ width: '90%', height: '95%' }} />
        </View>
        <View style={{ flex: .6, justifyContent: 'center' }}>
          <View style={{ flex: .35 }}>
            <Text style={{fontSize:12,color:Colors.ColorSecundario}}>{item.title}</Text>
          </View>
          <View style={{ flex: .65, justifyContent: 'center' }}>
            <Text style={{fontSize:10,color:Colors.ColorSecundario}}>{item.description}</Text>
          </View>
        </View>
      </View>
    </View>
    </TouchableOpacity>
  );

  
导出默认功能主屏幕(){
const[isLoading,setLoading]=useState(true);
const[data,setData]=useState([]);
const actualNoticia=数据[2];
useffect(()=>{
取('http://newsapi.org/v2/top-headlines?country=mx&apiKey=7b1bcdb1cbe04f709b69c0ef4f9c323b')
.then((response)=>response.json())
.then((json)=>setData(json.articles))
.catch((错误)=>console.error(错误))
.最后(()=>setLoading(false));
}, []);
常量renderItem=({item})=>(
{item.title}
{item.description}
);

我需要使用如下
useState
使用onPress

功能更改项目的actualNoticia值

export default function HomeScreen() {
  const [isLoading, setLoading] = useState(true);
  const [data, setData] = useState([]);
  const [actualNoticia, setActualNoticia] = useState({});

  useEffect(() => {
    fetch('http://newsapi.org/v2/top-headlines?country=mx&apiKey=7b1bcdb1cbe04f709b69c0ef4f9c323b')
      .then((response) => response.json())
      .then((json) => setData(json.articles))
      .catch((error) => console.error(error))
      .finally(() => setLoading(false));
  }, []);

  const renderItem = ({ item }) => (
    <TouchableOpacity onPress={()=>{setActualNoticia(item)}}>
    <View style={styles.itemHorizontal}>
      <View style={{ flex: .9, width: windowWidth * .95, padding: 10, backgroundColor: Colors.ColorPrincipal, borderRadius: 5, flexDirection: 'row' }}>
        <View style={{ flex: .4 }}>
          <Image source={{ uri: item.urlToImage }} resizeMode='cover' style={{ width: '90%', height: '95%' }} />
        </View>
        <View style={{ flex: .6, justifyContent: 'center' }}>
          <View style={{ flex: .35 }}>
            <Text style={{fontSize:12,color:Colors.ColorSecundario}}>{item.title}</Text>
          </View>
          <View style={{ flex: .65, justifyContent: 'center' }}>
            <Text style={{fontSize:10,color:Colors.ColorSecundario}}>{item.description}</Text>
          </View>
        </View>
      </View>
    </View>
    </TouchableOpacity>
  );
导出默认功能主屏幕(){
const[isLoading,setLoading]=useState(true);
const[data,setData]=useState([]);
const[actualNoticia,setActualNoticia]=useState({});
useffect(()=>{
取('http://newsapi.org/v2/top-headlines?country=mx&apiKey=7b1bcdb1cbe04f709b69c0ef4f9c323b')
.then((response)=>response.json())
.then((json)=>setData(json.articles))
.catch((错误)=>console.error(错误))
.最后(()=>setLoading(false));
}, []);
常量renderItem=({item})=>(
{setActualNoticia(项目)}}>
{item.title}
{item.description}
);

Thansk获取帮助:)