如何将变量传递给已经具有变量的功能组件?

发布于 2025-02-06 03:05:52 字数 944 浏览 3 评论 0原文

我在这里有一个孩子功能组件(Commafunc(e)),必须使用事件变量来调用以进行进一步处理,现在我需要做的事情,我似乎无法做到的,是返回在此处声明的变量之一commafunc子组件(realOutput)到addCommatonumber父零件(也许是props?),

我称之为parent

export default class home extends Component {
  render() {
    return (
      <AddCommaToNumber />
    )
  }
}

the parent component:parent component(addcommatonumber.js),我称之为子component:child component:

function AddCommaToNumber() {
const [value, setValue] = React.useState("");

return (
    <div>
        <input
        value={value}
        onChange={(e) => { CommaFunc(e); setValue(e.target.value); }}
        type="text"
        />
        </div>
    );
}

child component:child component:the child component(commafunc.js): (我需要以某种方式将此RealOutput传递给AddCommatonumber组件)

export default function(e) {
    let realOutput = 100;
}

任何提示或帮助都将不胜感激!

I have a child functional component here(CommaFunc(e)) which has to be called with a variable of event for further processing, now what I need to do and I seem to can't, is return one of the variables declared in the CommaFunc child component(realOutput) to the AddCommaToNumber parent component (maybe as props?)

Where I called the parent component:

export default class home extends Component {
  render() {
    return (
      <AddCommaToNumber />
    )
  }
}

The parent component(AddCommaToNumber.js), and where I called the child component:

function AddCommaToNumber() {
const [value, setValue] = React.useState("");

return (
    <div>
        <input
        value={value}
        onChange={(e) => { CommaFunc(e); setValue(e.target.value); }}
        type="text"
        />
        </div>
    );
}

The child component(commaFunc.js): (I need to somehow pass this realOutput to the AddCommaToNumber component)

export default function(e) {
    let realOutput = 100;
}

Any hints or help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文