简体   繁体   English

如何使用 TextArea ReactJs 中的按钮正确返回 const

[英]how to correctly return a const with a button in a TextArea ReactJs

I would like to explain my problem of the day.我想解释一下我今天遇到的问题。

I have 2 const我有 2 个常量

const a = data.hi?.map((e) =>
    e?.hello?.label.toString()
);


const b = data.hi?.map((e) =>
 e?.bye?.label.toString());

currently, I have 2 buttons目前,我有 2 个按钮

<>
  <Button> A </Button>

  <Button> B </Button>
</>

I also have input text and state我也有输入文本和 state

const [text, setText] = useState("");

   <TextArea value={text} />

and so I am looking for when I click on button "A", it returns the value of my const "a" in my TextArea.所以我正在寻找当我点击按钮“A”时,它会在我的TextArea中返回我的const“a”的值。

I am open to any proposal thank you very much.我愿意接受任何建议,非常感谢。

thanks, Neff谢谢,内夫

it's simple这很简单

<Button onclick={() => {setText(a)}>
   A
 </Button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM