将子组件中函数中存储的值传递给React中的父子

问题描述 投票:0回答:1

下面是我的代码。

儿童部分

  const onSave = () => {
    var val = value
    props.onSave();
  }

<div onClick={() => { onSave() }}>
            <CheckButton variant="contained" text-align='center' />
          </div>

父组件

export const Card = (props) => {
    const onSave = (val) => { [I WANT TO ACCESS val within here] }
}


<TextInputContainer onSave={() => onSave()} />

有什么方法可以访问父组件中的变量val?该代码被大截断。实际代码使用Redux。

javascript reactjs react-props
1个回答
0
投票

react的createRef有助于u访问react组件的值:

© www.soinside.com 2019 - 2024. All rights reserved.