首页 > 解决方案 > 如何在反应中使用道具将数据获取到父组件?

问题描述

主页.js

import React from 'react';
import {Overlay} from "./MainOverlay";
const MainPage = () => {
  return (
    <View style={[styles.center, {top: 50}]}>
      ........some code.........
      <Overlay data1={somedata1},data2={somedata2}/>      //passing some data as props, I need some data to be returned back here
      ........some code.........
    </View>
  );
}

export default MainPage;

MainOverlay.js

const Overlay = (props) => {
return(
   .......some code.......
   <View>{props.data1}</View>
   <View>{props.data2}</View>
   <InputText/>        //for user to enter some data
   <Button title="save" onClick={}/> //here i need to pass the input text data "x" to Mainpage.js, is there a way to send data to mainpage.js?
);
}
export  Overlay;

我是 react native 的初学者,所以我不知道它是如何工作的。

当我按下叠加层中的保存按钮时,我需要将数据从叠加层发送到主页,这就是我的问题

标签: reactjsreact-native

解决方案


推荐阅读