首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应本机标题状态,以屏幕可能吗?

问反应本机标题状态,以屏幕可能吗?
EN

Stack Overflow用户
提问于 2022-01-29 15:55:24
回答 1查看 59关注 0票数 0

我有一个标题,其中是一个输入字段。这能把这个值传递给我的屏幕文件吗?

Header.js

代码语言:javascript
复制
import React, { useCallback } from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, TouchableOpacity, Dimensions, Platform, TextInput } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { Feather, AntDesign } from '@expo/vector-icons';
import Constants from 'expo-constants';

const width = Dimensions.get('window').width;

const headerHeight = 50;

const headerMessages = (text) => {
  const navigation = useNavigation();

  const [search, setSearch] = React.useState('');

  const handleChangeInput = React.useCallback((e) => text(e));
  
  const handleGoBack = useCallback(() => {
    navigation.goBack();
  });
  return (
    <View style={styles.container}>
      <View style={styles.topHeader}>
        <StatusBar color="#333" />
        <Text style={styles.headerTitle}>Messages (0)</Text>
      </View>
      <View style={styles.searchContainer}>
        <TextInput value={search} style={styles.searchInput} onChangeText={handleChangeInput} placeholder='Search Field' />
      </View>
    </View>
  )
};


})

export default headerMessages;

Message.js

代码语言:javascript
复制
import * as React from 'react';
import { StyleSheet, Text, View, Pressable } from 'react-native';

const Messages = (props) => {
  console.log(props.text);

  
  return (
    <View style={s.container}>
      <Text>Messages</Text>
    </View>
  )
};

..........................................................................................................................

EN

回答 1

Stack Overflow用户

发布于 2022-01-29 16:12:59

如果您希望Message.js文件中的“search”状态值,在这种情况下,在Message.js文件中初始化搜索并将setSearch钩子作为回调函数传递到Header.js文件中。在Header.js中,获取状态作为支持,并在文本输入中设置值。这样,您将在message.js文件中获得搜索值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70907178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档